Space-Filling Curves

Hilbert, Peano, and Z-curves — continuously mapping 1D to 2D

Space-Filling Curves: A space-filling curve is a continuous curve whose image contains every point in a 2D region. Hilbert (1891) constructed an iterative curve where each order subdivides squares into 4 smaller ones, connected in a U-shape. At order n, the curve visits all 4^n cells of a 2^n × 2^n grid exactly once — making it a bijection between [0,1] and [0,1]². Key property: the Hilbert curve preserves locality better than the Z-curve (Morton order): nearby points on the 1D curve tend to be nearby in 2D. This makes it ideal for cache-friendly 2D data layouts and spatial indexing (R-trees, geohashing).