AlgoScope

Fenwick Tree

Data structureadvancedRange Structuresalso called binary indexed tree, BIT

An array where cell i holds the sum of a range whose length is its lowest set bit.

Result · step 8 of 10Fenwick Tree: Build from eight values
03✓15✓25✓311✓44✓510✓62✓7238i

Cell 7 covers 7 to 7 and now holds 2. Its parent is 7 + lowbit(7) = 8, so 2 is folded in there too.

Open in the player →or start at step 8

What you will see

Query jumps i -> i minus lowbit(i); update jumps i -> i plus lowbit(i); bits shown alongside.

How fenwick tree works →

Cost

prefix queryO(log n)
point updateO(log n)
buildO(n)
SpaceO(n)

How you work with it here

play it through, step one change at a time, scrub to any step, run it on your own input, try operations in any order.

Screen readers: Each element is an accessibility element with position, value and state; structural changes are announced per step.

Reduced motion: Elements appear at their destination with a crossfade; no travel longer than the element's own size.

Leads to

Topics that need this one first.

Taught by the same lesson

Fenwick Tree covers these too, in the same run.