AlgoScope

Range Tree

Data structureexpertRange Structures

A BST on one coordinate with a secondary structure per node for orthogonal range queries.

Decision · step 4 of 5Interval, kd and Range Trees: Range tree: canonical subtrees answer in y
2468✓10121416node

Right boundary at 12, inside the x range, so its left subtree at 10 hangs towards the range. Its subtree is entirely inside 5-13 in x, so it is a canonical subtree: its sorted y values are 15, and 0 of them lie in 4-12, found by binary search. Running total 3.

Open in the player →or start at step 4

What you will see

A 2D query decomposes into O(log n) canonical nodes, each answering in its own dimension.

How interval, kd and range trees works →

Cost

buildO(n log n)
queryO(log^2 n + k)
SpaceO(n log 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.

Before this

Related

Taught by the same lesson

Interval, kd and Range Trees covers these too, in the same run.