TOPICS
Search

Shortest Path Problem


The shortest path problem seeks to find the shortest path (a.k.a. graph geodesic) connecting two specific vertices (u,v) of a directed or undirected graph. The length of the graph geodesic between these points d(u,v) is called the graph distance between u and v. Common algorithms for solving the shortest path problem include the Bellman-Ford algorithm and Dijkstra's algorithm.

This problem is central to route planning and pathfinding applications, where vertices and edges may represent intersections and roads in a weighted transportation network. When travel times depend on edge flows, each route used at equilibrium is a shortest path for the travel times induced by those flows. Adding an edge can raise the equilibrium travel time, as in Braess's paradox.

The Wolfram Language function FindShortestPath[g, u, v] can be used to find one (of possibly mutiple) shortest path between vertices u and v in a graph g.

The so-called reaching algorithm can solve the shortest path problem on an m-edge graph in O(m) steps for an acyclic digraph although it allows edges to be traversed opposite their direction and given a negative length.

Gholami and Hajiaghayi (2026) report an exact randomized single-source algorithm for undirected graphs with nonnegative real edge lengths in the comparison-addition model. On a graph with n vertices and m edges, its expected time is O(m+nlogloglogn). It terminates almost surely and every terminating run returns exact distances and a shortest-path tree on reachable vertices. GPT Astra assisted proof development. The released Lean model uses named external assumptions for static tree queries.

A customizable contraction hierarchy separates preprocessing of a fixed graph from the choice of nonnegative edge weights (Dibbelt et al. 2016). For an undirected graph, choose a vertex order and eliminate vertices in that order, adding shortcut edges to connect each pair of remaining neighbors of an eliminated vertex. For each choice of input weights, initialize new edges with infinite weight. Then process vertices in the same order, using each two-edge walk through the current vertex to lower the weight of the corresponding shortcut or original edge whenever the walk is shorter.

Each finite edge weight after customization is the length of a walk in the original graph. Conversely, a shortest path can be made to increase in rank and then decrease by replacing each interior local minimum in rank with its shortcut. Thus a query can run Dijkstra's algorithm from each endpoint, following edges toward higher ranks, and minimize the sum of the two distances over common reachable vertices. A recursive ordering by vertex separators places each separator after the components it separates (Dibbelt et al. 2016).


See also

All-Pairs Shortest Path, Bellman-Ford Algorithm, Dijkstra's Algorithm, Floyd-Warshall Algorithm, Graph Distance, Graph Geodesic, Longest Path, Reaching Algorithm

Portions of this entry contributed by Andreas Lauschke

Explore with Wolfram|Alpha

References

Dibbelt, J.; Strasser, B.; and Wagner, D. "Customizable Contraction Hierarchies." J. Exp. Algorithmics 21, Art. 1.5, 2016. https://doi.org/10.1145/2886843.Gholami, I. and Hajiaghayi, M. "Linear Single-Source Shortest Path, Almost." 25 Nov 2026. https://arxiv.org/abs/2611.34911.Gholami, I. and Hajiaghayi, M. "Undirected SSSP in Lean 4." 2026. https://github.com/igholami/sssp-lean.Pemmaraju, S. and Skiena, S. Computational Discrete Mathematics: Combinatorics and Graph Theory with Mathematica. Cambridge, England: Cambridge University Press, 2003.Skiena, S. Implementing Discrete Mathematics: Combinatorics and Graph Theory with Mathematica. Reading, MA: Addison-Wesley, pp. 224-227, 1990.Veritasium. "How Does Google Maps Actually Work?" May 30, 2026. https://www.youtube.com/watch?v=kS-CGkiPetQ.

Referenced on Wolfram|Alpha

Shortest Path Problem

Cite this as:

Weisstein, Eric W., with contributions by Andreas Lauschke. "Shortest Path Problem." From MathWorld--A Wolfram Resource. https://mathworld.wolfram.com/ShortestPathProblem.html

Subject classifications