Imagine dropping a million GPS pins on a map and then asking: "which pins are inside this rectangle?" The brute-force answer checks all one million. But real maps respond in milliseconds. The secret is a quadtree.
A quadtree is a tree in which every internal node represents a square region of 2-D space and has exactly four children — one for each quadrant: NW, NE, SW, SE. When a region contains too many points it gets subdivided, splitting into four smaller squares. Regions that are empty or sparse stay as leaves and are never touched during a search.
The result is a tree that mirrors the density of your data: crowded cities are represented by deep chains of tiny cells; empty oceans are a single leaf node. A spatial query descends only the branches that overlap the query region, skipping everything else.
Extending the idea to three dimensions gives an octree: each node splits a cube into eight sub-cubes (octants). The logic is identical; the branching factor doubles. Octrees are the workhorse of 3-D rendering, LiDAR point clouds, and physics engines.
Both structures trace back to Raphael Finkel and Jon Bentley (1974), who introduced the quad-tree for efficient 2-D range searching. They are now so ubiquitous that every major game engine, GIS platform, and graphics library ships them as a built-in primitive.
Comments
Loading comments...