Skip to content

Trees

Segment trees and Fenwick trees

Members: Free account

Lessons on this topic

Intermediate · 20 minYou are hereRead

Prefix sums

Storing the running totals of an array gives the sum of any range in one subtraction, but changing one value means updating every total after it.

Intermediate · 30 minYou are hereRead

Segment trees

A tree whose every node holds the sum of a stretch of the array answers any range sum and any update in about log₂ n steps.

Intermediate · 20 minYou are hereRead

Fenwick trees

An array in which cell i holds the sum of a stretch whose length is the lowest set bit of i gives prefix sums and updates in about log₂ n steps with a few lines of code.

Phasorium

Account

Sign inWith Google, GitHub or your email

Subjects

Site

Look