AlgoScope

Segment Tree Query and Update

AlgorithmadvancedRange Queries

A query takes whole nodes inside the range and splits only the ones on its edge.

Decision · step 2 of 9Segment Tree: Sum of indices 2 to 5
5831678136✓4106202108current

Node 1 covers indices 0 to 7, holding 36. That straddles the edge, so split into both children.

Open in the player →or start at step 2

What you will see

Nodes whose ranges are fully inside light up and stop; partial ones recurse.

How segment tree works →

Cost

BestO(log n)
AverageO(log n)
WorstO(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: Structure nodes announce the range they cover and their value; each step announces which nodes answer the query.

Reduced motion: Contributing nodes highlight statically; no path animation.

Before this

Leads to

Topics that need this one first.

Taught by the same lesson

Segment Tree covers these too, in the same run.