Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

A chalk plan

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year.

See plansStart free instead

Module 09 · DSA · Four patterns the ladders lean on · about 15 min to read

Play it as a journeyTutor comes with a plan

One array, one trick: the Fenwick tree

Rotations and Range Trees
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