Binary Indexed Tree(BIT) also known as Fenwick Tree is a tree based advanced data structure that can be used to store and calculate cumulative sum or frequency. BIT is more efficient than other data structures (like Segment Tree and other RMQ) considering the time complexity, memory complexity and Line of Code.
Binary Indexed Tree(BIT) also known as Fenwick Tree is a data structure providing efficient methods for calculation and manipulation of the prefix sums
of a table of values. It was proposed by Peter Fenwick in 1994.
BIT primarily solve the problem of balancing prefix sum calculation efficiency with element modification efficiency. The efficiency of these operations comes as a trade-off - greater efficiency in prefix sum calculation is achieved by pre-calculating values, but as more values are pre-calculated more must be re-calculated upon any modification to the underlying value table.
The initial building of BIT requires O(nLogn)
time. But it can effectively run a range query on the built tree in O(logn)
time and also update the tree in O(logn)
time. Most importantly BIT can store the frequency table or the build tree in O(n)
memory space.
Use this tag when you are asking a problem related to Binary Indexed Tree. You should include code snippet or pseudo-code if necessary.
Referance