Quadtrees for dense neighborhoods 00:00:01 The fifth restaurant arrives I'm mapping five restaurants in a city block, but my leaf can only hold four. When the fifth one arrives, I have to decide how to handle the overflow without overcomplicating the whole map. The first four fit. Predict what happens when the fifth enters this same leaf. Do we cut the entire city into smaller squares, or just the full square? Meanwhile, rural areas with no restaurants stay as single coarse cells, avoiding unnecessary subdivision and saving memory. A point-region quadtree partitions space according to fixed midlines at each node. The limit of four is our chosen leaf policy. Other implementations choose different capacities or keep data at different places. 00:00:46 Split just the crowded square I split the full leaf into four child quadrants, each now capable of holding up to four points, ensuring the map adapts to local density. Redistribute all five entries by their coordinates. In one possible arrangement, two go northwest and one goes to each of the other three children. The total stays five. Remote rural cells remain unsplit, preserving shallow depth and minimizing computational overhead across the entire map. Route a point on a shared midline consistently, for example east on a vertical tie and north on a horizontal tie. Every restaurant needs one owner for insertion, lookup, deletion and movement. 00:01:28 Descend only where a query can reach When querying a 200-meter radius around a customer, only two of the four child quadrants intersect the search area. Skip the two disjoint child bounds at this branch. They cannot contain a point in the circle, provided every point really is stored under the bounds recorded for its child. For the two intersecting quadrants, I test each point’s actual distance to the customer, ensuring no false negatives. Skipping half the children at this particular node does not promise half the total query cost. The visited children may contain most of the restaurants. Count actual visits and distance checks. 00:02:06 What if many points share one address? If ten restaurants all share the same address, repeated splits won’t separate them, leading to infinite recursion. Choose a stopping rule. At a configured maximum depth or minimum cell size, keep an overflow bucket. Alternatively, recognize identical coordinates and group their identifiers as a single location. If ten restaurants share this address and grouping is enabled, one location points at ten distinct identifiers. A radius query must still be able to return all ten. At the depth limit a leaf may hold more than four records. That exception preserves correctness; it trades additional per-leaf scanning for bounded tree depth when positions cannot be separated. 00:02:48 Choose adaptive detail deliberately In dense areas, fine pruning reduces the number of distance checks, while sparse regions avoid unnecessary splits. Compare with a fixed grid on city-centre clusters, countryside and moving points. Count node visits, distance checks, updates and memory. No universal percentage describes the improvement. At the map edges, I verify results against brute-force search to ensure no restaurants are missed during pruning. Moving a restaurant means removing the old entry and inserting the new coordinate under the same ownership rule. If you also merge sparse children, test split and merge thresholds with a point oscillating across the boundary.