Skip to content

K-d Tree

A k-d tree organizes multidimensional records by recursive binary splits on coordinate keys, enabling bounded-region search and pruning.

Version
v1 · 2026-10-03 · History
Domain-specific #
13357
Domain group
Applied Sciences & Engineering
Origin domain
Computer Science & Software Engineering
Subdomains
Associative Retrieval, Spatial Data Structures → Computer Science & Software Engineering
Aliases
Kd Tree, Multidimensional Binary Search Tree

Core Idea

A k-d tree stores records with k coordinate keys in a binary tree. Each node compares one selected coordinate; lower and higher branches recursively restrict where descendants may lie. Those region bounds permit safe pruning when a query cannot intersect a subtree. Bentley's original definition cycles discriminators by level. Median splitting balances the tree but is an optimization, not the definition.[1]

How would you explain it like I'm…

Left-Right, Up-Down Sorting

Imagine sorting toys spread on the floor by asking yes-or-no questions. First you ask, 'Is it on the left half or the right half?' Then for each side you ask, 'Is it near the top or the bottom?', and you keep taking turns like that. A K-d Tree is a computer's way of sorting things like this, so when it looks for something it can skip whole parts of the floor where the thing can't be.

Taking-Turns Splitting Tree

A K-d Tree is a way for computers to organize items that each have several numbers describing them, like a spot on a map with an east-west number and a north-south number. It's built like a branching tree. At each branch point, the computer picks one of the numbers and sends smaller values one way and bigger values the other way. In the original version, the number it checks switches at each level, first east-west, then north-south, and so on. Each branch ends up covering one box-shaped region, so when you search, the computer can skip whole branches whose region can't have what you want. How fast it works depends on how well the tree is built.

Multidimensional Binary Search Tree

A K-d Tree (k-dimensional binary search tree) stores records that each have k coordinates. Each node chooses one coordinate, called the discriminator, and sends lower values to one side and higher values to the other; in Bentley's 1975 version, the discriminator cycles through coordinates level by level. Following a path of these tests narrows each subtree to a bounded region of space, so a search can skip a subtree whose region can't contain an answer. It was designed for searching when there's no single main key to sort by. Building it with medians keeps it balanced, but balance isn't part of the definition—an unbalanced K-d Tree is still one, just possibly slow. Nearest-neighbor search isn't guaranteed to be fast; performance claims depend on how the tree is built, the query, and the number of dimensions.

 

A K-d Tree is a binary search tree generalized to records with k coordinate keys. Each internal node designates a discriminator coordinate and partitions descendants into lower and higher values on that coordinate. In Bentley's 1975 formulation, discriminators cycle with depth. The sequence of tests along a root-to-node path bounds each subtree to an axis-aligned region of k-space, which enables pruning: a range or neighbor query can discard any subtree whose region cannot intersect the answer set. The structure was designed for associative retrieval where no single key is inherently primary. Median splitting yields balance, but balance is not definitional; an unbalanced K-d Tree is still valid and may perform badly. Performance claims are conditional. Bentley reported empirically logarithmic average behavior for the nearest-neighbor method known at the time and noted its limitations, and Friedman, Bentley, and Finkel later developed a modified best-match algorithm. Any average-case statement must state the construction, the query type, and the dimensionality conditions.

Scope of Application

Bentley proposed exact, partial, region and nearest-neighbor retrieval for multiattribute files. His city example asks for locations inside the Oklahoma Panhandle rectangle of 36°30′–37° latitude and 100°–103° west longitude; subtrees with disjoint bounds can be skipped. He also proposed nearest-city and speech-template uses, not documented deployments. His median OPTIMIZE routine rebuilds in O(n log n), whereas dynamic updates can unbalance a tree.[1]

Clarity

In Bentley's two-dimensional Figure 1, a root x comparison followed by a y comparison gives rectangular bounds for descendants. A subtree confined to x=50–100 cannot contain points in a query whose x maximum is 40. Nearest-neighbor search is subtler: the other side of a split may still hold a closer point and can be skipped only with a distance lower bound.[1]

Manages Complexity

One structure supports several query kinds without a full scan when bounds prune effectively. It also incurs construction and maintenance costs, and broad output regions or high dimension can leave many branches plausible. Bentley reported empirical average logarithmic nearest-neighbor behavior for an early method, not a universal worst-case guarantee; partial-match bounds can be polynomial even in ideal trees.[1]

Abstract Reasoning

Ancestor discriminator comparisons intersect into a descendant hyperrectangle. If that box is disjoint from the query region, no descendant can qualify. Median selection makes approximately equal child sizes; O(n) work per level over O(log n) levels yields O(n log n) build work. Query cost still depends on how many boxes intersect the target and how many results must be returned.[1]

Knowledge Transfer

City coordinates, speech features and other comparable multikey records can use the same binary-bound invariant; their workloads need not yield the same performance. Live Tree Data Structure is the strict parent. The live Partition captures a related division, while live Index is an auxiliary pointer table not required by Bentley's record-at-node structure. Neither prime is a forced strict parent.

Relationships to Other Abstractions

Local relationship map for K-d TreeParents appear above the current abstraction, mutual partners to the right, and children below. Node labels state whether each abstraction is prime or domain-specific; colors identify relation types.K-d TreeDOMAINDomain-specific abstraction: Tree (Data Structure) — is a kind ofTree (DataStructure)DOMAIN

Current abstraction K-d Tree Domain-specific

Parents (1) — outgoing typed relations

  • K-d Tree is a kind of Tree (Data Structure) Domain-specific

    A k-d tree is a tree data structure whose nodes recursively split records by coordinate discriminators.

Hierarchy paths (6) — routes to 5 parentless roots

Neighborhood in Abstraction Space

K-d Tree sits in a sparse region of the domain-specific corpus (63rd percentile for distinctiveness): few abstractions share its structure, so a faithful description tends to retrieve it precisely.

Family — Storage & Lookup Data Structures (22 abstractions)

Nearest neighbors

Computed from structural-signature embeddings · 2026-11-14

References

[1] Bentley, original k-d-tree paper, Communications of the ACM 18 (1975), pp. 509–517. registry ↩a ↩b ↩c ↩d ↩e