⚡ Build the skills to land top-paying quant jobs. Offer ends in 17d 22h 20m 21s17 days 22 hours 20 minutes 21 seconds.
⚡ Build the skills to land top-paying quant jobs. Offer ends in 17d 22h 20m 21s17 days 22 hours 20 minutes 21 seconds.

Sign in to watch this lesson
Algorithms - Trees and Range Queries · 4:59
A Fenwick tree stores, at every index, the sum of a run of values as long as the index's lowest set bit, which i & -i extracts in one instruction. Queries strip bits off the index and updates add them, so both take O(log n) in about a dozen lines of code. We draw the staircase of bars, walk sum(13) and add(10), handle range updates with two trees, find where a running total first reaches a target with a single descent, and time it on a Mac against square-root blocks, a plain array and a naive range loop.