I plan to implement Fenwick tree in Java. That is, the Fenwick tree, which allows you to alternate range requests with the addition / removal of elements.
All the implementations and samples I saw so far for the Fenik trees of a fixed size, where the number of elements is known before the frequency preprocessing. They use a fixed-size array, so it’s not possible to add or remove elements after preprocessing. (Well, it's possible, but I will need to rebuild the structure).
I was thinking about expanding, TreeMapor maybe AbstractMap, but since it TreeMapis actually a red-black tree, I do not know how to implement red-black mechanics (so that the tree remains balanced) without losing the cumulative sums of nodes involved in the rebalancing process.
So, I thought that maybe I should use a different approach: why not expand or adapt simple random access ArrayListand recalculate all cumulative amounts when resizing the underlying array? It certainly will, but hey, this is what it does HashMap.
That's why I wanted to first ask here if someone had already done this, and check which approach you think is best.
source
share