AlgoScope

KD-Tree

Data structureadvancedRange Structures

A space-partitioning BST alternating split axes; nearest-neighbour and range search in k dimensions.

Decision · step 2 of 8Interval, kd and Range Trees: kd-tree range search across alternating splits
(3,7) x(5,15) y(8,18) x(10,10) x✓(15,5) y(12,12) x(18,8) ynode

(10,10) splits on x = 10. It is inside the rectangle: report it. The rectangle's x range is 4-13, so it crosses the split: both sides must be searched.

Open in the player →or start at step 2

What you will see

Splitting lines drawn on the plane alternate vertical and horizontal; a search prunes half-planes.

How interval, kd and range trees works →

Cost

buildO(n log n)
nearest neighbourO(log n) average
range queryO(sqrt(n) + k)
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.

Related

Taught by the same lesson

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