Interactive application
Interactive
Overview · selected highlights

Fenwick trees

A Fenwick tree explained through the ranges it stores. Follow prefix queries and updates through an array, then extend the bookkeeping to range operations and two dimensions, with intermediate state showing why each jump is useful.

Binary structure makes a range sum cheap
UpdatePartitionSum
Brochure →Open project ↗
  1. [ ]

    Partition the range

    Each array entry stores a particular aligned interval.

  2. Σ

    Gather a prefix

    Combine disjoint stored intervals to answer a cumulative query.

  3. +

    Propagate an update

    Visit the entries whose represented intervals contain the change.

  4. ▦

    Extend the structure

    Inspect range-update bookkeeping and the two-dimensional construction.

The bit operation is a compact encoding of visible interval structure.

Basic
Basic
Range-Updage
Range-Updage
Range-Update Range-Query
Range-Update Range-Query