AlgoScope

Segment Tree

Data structureadvancedRange Structures

A binary tree whose leaves are the array and whose every parent summarises its two children.

Result · step 8 of 9Segment Tree: Build a sum tree
58✓316✓78✓136✓410✓620✓210✓8current

Node 1 covers indices 0 to 7. Its children hold 16 and 20, so it holds 36.

Open in the player →or start at step 8

What you will see

A query lights up O(log n) nodes that exactly tile the range; an update walks one root-to-leaf path.

How segment tree works →

Cost

buildO(n)
queryO(log n)
updateO(log n)
SpaceO(n)

How you work with it here

play it through, step one change at a time, scrub to any step, run it on your own input, try operations in any order.

Screen readers: Each element is an accessibility element with position, value and state; structural changes are announced per step.

Reduced motion: Elements appear at their destination with a crossfade; no travel longer than the element's own size.

Leads to

Topics that need this one first.

Taught by the same lesson

Segment Tree covers these too, in the same run.