A quadtree recursively subdivides a 2D domain into as many as four quadrants per node. In point-region (PR) and region quadtrees, each subdivided node owns four child regions — NW, NE, SW, SE — although an implementation can keep empty quadrants as implicit slots instead of allocating child objects. A region holding too much (too many points, or a non-uniform block of pixels) splits into four equal sub-regions, each of which may split again, until every leaf is “simple enough” — holds at most a small bucket of points, or is a uniform block. A point at (x, y) is placed by repeatedly asking which quadrant it falls in and descending, so spatial neighbors end up in the same or adjacent leaves.

Be honest about what it is not: a quadtree is a spatial-partitioning tree, not a balanced O(log n) search tree. It has no rotation or fill invariant like an AVL Tree or a B-tree. A point quadtree’s depth follows insertion order and point placement. A PR quadtree’s depth follows clustering within a fixed root region and stops only at a defined minimum cell size, coordinate precision, or overflow policy. A region quadtree over a 2^r × 2^r raster has depth at most r. What these variants buy is spatial pruning: a range or nearest-neighbor query can discard whole regions that do not intersect the search.

Core shape: rectangular region → split into 4 equal quadrants (NW/NE/SW/SE) when overfull → recurse until leaves are simple → point routed by quadrant containment → depth follows data distribution, not a balance invariant, O(n) storage.

Variants

The name covers a family that differs in what triggers a split and what a leaf stores:

  • Point quadtree (Finkel & Bentley, 1974). Each inserted point becomes an internal node and splits the plane at its own coordinates into four (generally unequal) quadrants — a direct 2D generalization of a Binary Search Tree. Its nodes do not carry fixed rectangular bounds unless the implementation adds them; shape depends on insertion order, so a bad order degrades it.
  • Point-region (PR) quadtree. Decouples splitting from the data. Space is cut into four equal quadrants regardless of point coordinates; a leaf bucket splits only when it exceeds capacity (often one point). Internal nodes are pure spatial subdivisions; leaves hold the points. The shape depends only on where the points are, not the order they arrived.
  • Region quadtree (image/raster). The domain is a 2ⁿ × 2ⁿ grid and each node covers a square block. A uniform block (all one color/value) is a leaf; a mixed block splits into four equal sub-blocks. Used for image compression and spatial occupancy — large empty or solid areas collapse to a single node.

Operations and use cases

Insert, search, and delete all follow the quadrant containing the target down to a leaf. The queries that make the structure worthwhile prune subtrees:

  • 2D range query — descend, skipping any quadrant whose rectangle does not intersect the query window; report points in the surviving leaves.
  • Nearest-neighbor — best-first / branch-and-bound over quadrants, pruning a quadrant once its bounding box is farther than the current best.
  • Collision detection (broad phase) — objects sharing a cell (or an adjacent one) are collision candidates, replacing an O(n²) all-pairs check with a handful of local comparisons.
  • Image compression — a region quadtree merges uniform blocks into single leaves.
  • Geospatial and simulation — subdividing a map into cells for level-of-detail, terrain, or particle systems; the 3D cousin (the octree, eight children) drives Barnes–Hut n-body approximation.

Quadtree vs geohash

A Geohash encodes a point into a fixed-grid, sortable prefix; a PR or region quadtree is an adaptive tree whose cells subdivide only where the workload requires more resolution. Geohash is the better fit when an existing sorted index, cache, or shard key should produce spatial candidates. A PR or region quadtree is the better fit for mutable in-memory workloads that benefit from explicit region bounds, local subdivision, collision broad-phase, or sparse raster compression.

The boundary cost differs. Adjacent points can fall into different geohash prefixes, so a proximity query must inspect neighboring cells and filter candidates by exact geometry or distance. An adaptive PR quadtree avoids one fixed global cell size but still needs a maximum depth or minimum cell size for coincident and near-coincident points. For paged durable storage, prefer the database’s spatial index unless the fixed-prefix key is itself the requirement. Geohash carries the encoding, Redis and Elasticsearch examples, boundary algorithm, and R-tree/GiST comparison; Indexes covers the broader database-index tradeoff.

Complexity

For the point and PR variants, let n be the number of points, h the actual tree depth, v the visited or intersected nodes, and k the results. Point operations are O(h); the O(log n) entries below are distribution assumptions, not structural bounds. For a PR quadtree, h is additionally capped only when the implementation defines a finite root region and a minimum cell size, finite coordinate precision, or another terminal overflow rule. A region quadtree over a 2^r × 2^r raster instead has h ≤ r.

OperationAverage (uniform)Worst (clustered)Space
InsertO(log n)O(n)O(n)
Point searchO(log n)O(n)
Range queryO(v + k)O(n)
Nearest neighbor~O(log n) expectedO(n)
Build (n points)O(n log n)O(n²)O(n)

With roughly uniform occupancy and a query window that intersects a bounded number of cells at the chosen depth, v remains small relative to n; it is not generally O(log n).

The point-quadtree worst case comes from insertion order and spatial placement, just as a binary search tree can become a chain. The PR-quadtree worst case comes from repeated subdivision of one region; coincident points cannot be separated by geometry at all, so the implementation must keep an overflow bucket or stop at a declared depth. Coordinate resolution bounds depth only when coordinates are quantized and the split arithmetic respects that finite domain. These are variant-specific limits, not a universal O(log n) guarantee.

Reference drawer

Questions

References