Algorithms and Data Structures · Senior · Question 7 of 75

What problem does a Fenwick tree (binary indexed tree) solve?

Explanation

Plain prefix sums make queries O(1) but updates O(n). A Fenwick tree balances both at O(log n) using the lowest set bit of the index (i & -i) to jump between ranges.

Further reading

Problem with a question

Algorithms and Data Structures · Senior · question 7

Test yourself

Take the Algorithms and Data Structures · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz