Contraction Hierarchies (CH) is a graph preprocessing algorithm that accelerates shortest-path queries on road networks by orders of magnitude compared to Dijkstra's algorithm. It works by assigning an importance order to every node in the graph and then 'contracting' them one by one, adding shortcut edges to preserve the shortest-path distances between the remaining, more important nodes.
Glossary
Contraction Hierarchies

What is Contraction Hierarchies?
A speed-up technique for shortest-path routing that preprocesses a road network graph by ordering and contracting nodes, enabling millisecond query times.
During a query, a bidirectional Dijkstra search is performed, but it only traverses edges leading to nodes of higher importance. This drastically limits the search space, as the forward and backward searches meet at the highest-importance node on the optimal path. CH is a foundational technique in modern logistics engines, enabling real-time dynamic route optimization for continent-scale road networks.
Key Characteristics of Contraction Hierarchies
Contraction Hierarchies (CH) is a speed-up technique that transforms a static road network graph into a multi-layered structure, enabling shortest-path queries to be answered in milliseconds. The following cards break down the core mechanisms that make this possible.
The Node Contraction Operation
The preprocessing phase iteratively removes nodes from the graph one by one, in a specific order of 'importance'. When a node v is contracted, it is removed, and shortcut edges are added between its neighbors to preserve the shortest path distances. A shortcut is only added if the path through v was the unique shortest path between two neighbors. This process effectively encodes all-pairs shortest-path information into a sparser but augmented graph.
Bidirectional Query Algorithm
Queries are executed as a bidirectional variant of Dijkstra's algorithm. The forward search from the source only traverses edges leading to nodes with a higher importance (rank), while the backward search from the target traverses edges from nodes with a lower importance. Both searches meet at the highest-ranked node on the shortest path, known as the 'meeting point'. This drastically limits the search space to a small, cone-shaped subgraph.
Node Ordering Heuristics
The performance of CH critically depends on the order in which nodes are contracted. Poor ordering leads to an explosion of shortcuts and degrades query speed. Common heuristics combine several factors to compute a priority score for each node:
- Edge Difference: The difference between shortcuts added and edges removed.
- Uniformity: Penalizes contracting nodes that create dense clusters of shortcuts.
- Cost of Contraction: The raw computational cost of simulating the contraction. Nodes with the lowest priority score are contracted first.
Static Graph Requirement
CH is fundamentally a static graph algorithm. The preprocessing step is computationally intensive and must be re-run from scratch if the underlying road network topology or edge weights (e.g., average travel times) change significantly. This makes it ideal for core routing on stable maps but requires a complementary dynamic layer, such as Time-Dependent VRP solvers or Model Predictive Control, to handle real-time traffic incidents or road closures during the actual route execution.
Perfect Query Optimality
Unlike many heuristic or approximate methods, Contraction Hierarchies is an exact algorithm. The bidirectional query on the augmented graph is mathematically proven to find the identical optimal shortest path as a full Dijkstra's search on the original graph. This property is non-negotiable for logistics applications where precise distance and time calculations are required for cost estimation, driver payroll, and guaranteed service level agreements.
Contraction Hierarchies vs. Other Pathfinding Algorithms
A technical comparison of Contraction Hierarchies against Dijkstra's algorithm and A* search for shortest-path queries on large-scale road networks, highlighting preprocessing requirements, query performance, and operational suitability.
| Feature | Contraction Hierarchies | Dijkstra's Algorithm | A* Search |
|---|---|---|---|
Preprocessing Required | |||
Preprocessing Time | Minutes to hours | None (0 sec) | None (0 sec) |
Query Time Complexity | O(log N) typical | O(E + V log V) | O(E) worst-case |
Heuristic Required | |||
Handles Dynamic Edge Weights | |||
Memory Footprint | High (augmented graph) | Low (original graph) | Low (original graph) |
Optimal for Static Road Networks |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Frequently Asked Questions
Core questions about the mechanics, application, and performance of Contraction Hierarchies in modern logistics and autonomous supply chain routing engines.
A Contraction Hierarchy (CH) is a speed-up technique for shortest-path queries on road networks. It works by preprocessing the graph: nodes are ordered by 'importance,' and each node is 'contracted' by removing it from the graph while adding shortcut edges to preserve shortest-path distances between its more important neighbors. A query then runs a bidirectional Dijkstra search that only visits nodes of increasing importance, drastically reducing the search space. This enables millisecond-level path computations on continent-sized graphs, making it orders of magnitude faster than a standard Dijkstra's algorithm for repeated queries in dynamic route optimization.
Related Terms
Contraction Hierarchies are part of a broader ecosystem of shortest-path algorithms. These related concepts define the landscape of modern route optimization.
Bidirectional Search
A strategy that runs two simultaneous searches: one forward from the origin and one backward from the destination. The algorithm terminates when the two search frontiers meet. Contraction Hierarchies inherently leverage a bidirectional approach, but with a critical advantage—the preprocessing step orders nodes so that the forward and backward searches only need to traverse a small, upward-closed subset of the graph.
Highway Hierarchies
A predecessor to Contraction Hierarchies that also uses preprocessing to accelerate queries. It identifies and contracts low-importance local roads around each node, creating a hierarchy of increasingly important highway levels. While effective, Contraction Hierarchies are generally simpler to implement, offer faster query times, and have become the more widely adopted standard in production routing engines.
Graph Preprocessing
The offline phase where the road network is transformed to enable sub-millisecond queries. For Contraction Hierarchies, this involves:
- Node Ordering: Heuristically ranking nodes by importance using edge difference metrics.
- Node Contraction: Removing nodes one by one and adding shortcut edges to preserve shortest-path distances between remaining neighbors. This one-time computation is what enables the dramatic query-time speedup.
Shortcut Edge
A synthetic edge inserted during the contraction of a node v. If the only shortest path between neighbors u and w passes through v, a shortcut edge u → w is added with a weight equal to the sum of u → v and v → w. This preserves all shortest-path distances in the remaining graph. During a query, the algorithm only relaxes edges leading to nodes with a higher rank, guaranteeing correctness.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us