Why it matters

KD-trees enable spatial + nearest-neighbor search. Understanding shapes ML + graphics + GIS work.

Advertisement

The architecture

Node: point + axis for split.

Left subtree: points less along axis; right: greater.

Rotate axis per level.

KD-tree structureSplit axisrotates per levelRecursive partitionbinary treeQuerysearch with pruningEffective for low dimensions; curse of dimensionality above ~20 dims
KD-tree navigation.
Advertisement

How it works end to end

Nearest neighbor: walk down; unwind checking if other side could have closer point.

Range query: report points in axis-aligned box.

Curse of dimensionality: efficiency degrades above ~20 dimensions.

Alternatives: ball tree, R-tree, LSH for high dimensions.