YOUTLDR

Google Maps is unreasonably fast. Let me explain

Veritasium

YouTLDR SummaryAuto transcript

contraction hierarchy

Google Maps uses a customizable contraction hierarchy. It pre-processes road networks to rank intersections by importance, then uses a bidirectional search up this hierarchy for speed. This is 35,000x faster than Dijkstra's algorithm for long routes.

  • πŸ—ΊοΈ The core algorithm is still based on Dijkstra's, a 70-year-old invention.
  • πŸš€ A-star, a variation of Dijkstra's, uses heuristics to prioritize nodes closer to the target, improving speed but not always for travel time.
  • ↔️ Bidirectional Dijkstra searches from both the start and end points simultaneously, reducing the search area by half.
  • πŸš— Road networks have a hierarchy (highways vs. local roads) that basic algorithms ignore, leading to inefficiencies.
  • ⏳ Pre-processing the network into a hierarchy takes hours but makes subsequent searches nearly instantaneous.

A map with a winding blue route connecting two red location pins, with the word 'How?' prominently displayed.