top | item 32187880

(no title)

gordaco | 3 years ago

Fenwick Trees (which, despite the name, are implemented using an array) allow counting prefix sums AND updating prefix sums in O(log n) time. Very useful when n is in the order of millions. I have used them a few times in Project Euler problems.

https://en.wikipedia.org/wiki/Fenwick_tree

discuss

order

nyanpasu64|3 years ago

Is it possible to implement a Fenwick tree using a tree, and support quickly adding and removing items as well as quickly shifting the positions of suffixes?

pjscott|3 years ago

Yes! This is both possible and fairly easy.

EnderShadow8|3 years ago

Segment trees are objectively superior in all ways except implementation length

almog|3 years ago

Another advantage to Fenwick Tree: while it shares asymptotic space complexity with Segment Tree, it has better constant factors, which can be useful in very restricted environments.