Module 09 · DSA · Four patterns the ladders lean on · about 15 min to read
One array, one trick: the Fenwick tree
Rotations and Range Trees · Open board
Range trees answer “what is the total of this stretch” while the numbers keep changing. This lesson builds the smallest one, inside a single array.
Lesson 79 of 96 in DSA
The rest of this lesson is part of a plan.
A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.
See plansAlready a member? Sign in
Or start free: a free account opens lessons 2 and 3 of every track.
In this lesson
- A ticket counter that never stops changing
- Lowbit: the size of the lowest bit that is on
- The Fenwick tree: each cell covers lowbit items ending at itself
- Asking: drop the lowest bit and hop
- Updating: add lowbit and climb
- A range is two questions
- Inversions: how out of order is a row
- The tree itself
- Building in one pass
- LC 307, Range Sum Query, Mutable
- LC 315, Count of Smaller Numbers After Self
- The inversion total, checked against brute force
- Edges and limits
Terms it explains: bit, lowbit, Fenwick tree, inversion, rank compression, Common mistakes.
Review DSA
Saved in this browser, and to your account when you sign in.