Shortest path problem

What Is the Shortest Path Problem?

The shortest path problem is a foundational problem in graph theory and combinatorial optimization that asks for the minimum-cost route between two vertices in a weighted graph, where cost is measured by the sum of edge weights along the path. It formalizes a question that arises whenever resources travel through a network: the lowest-latency route between two routers, the least-fuel path between cities, or the fewest hops through a social network. The problem is defined on directed or undirected graphs with non-negative or, in generalized forms, negative edge weights, and it has been studied since the 1950s when efficient algorithms first made large-scale computation tractable.

The shortest path problem sits at the intersection of algorithm design, operations research, and network analysis. The traveling salesman problem is a related but distinct combinatorial problem that requires visiting every node exactly once, making it NP-hard, whereas the single-source shortest path problem admits polynomial-time exact solutions for most practically relevant graph classes.

Graph-Theoretic Formulation

Formally, a weighted graph G consists of a vertex set V and an edge set E, with each edge carrying a real-valued weight. The shortest path from source vertex s to destination t is the sequence of edges with minimal total weight among all paths connecting s to t. If no path exists, the distance is defined as infinite. The problem has several standard variants: single-source (find shortest paths from one vertex to all others), single-pair (source to one specific destination), and all-pairs (find shortest paths between every pair of vertices). As covered in CMSC 451 lecture notes from the University of Maryland, the single-source and single-pair problems have the same worst-case complexity when solved by known algorithms, so the single-source case is the standard setting for algorithm analysis.

Negative-weight edges are permitted in generalized formulations but negative-weight cycles are not, because they make the shortest path undefined: traversing the cycle repeatedly decreases the total cost without bound.

Dijkstra's Algorithm and Bellman-Ford

The two classical single-source algorithms are Dijkstra's algorithm (1959) and the Bellman-Ford algorithm, developed around the same period. Dijkstra's algorithm operates by greedily expanding a priority queue of vertices ordered by their tentative distance from the source. It runs in O(V log V + E) time with a Fibonacci heap implementation and is optimal when all edge weights are non-negative, which covers the majority of practical network routing applications.

Bellman-Ford relaxes all edges V-1 times, where V is the number of vertices, producing an O(VE) algorithm. It is slower than Dijkstra's for graphs with non-negative weights, but it handles negative edge weights correctly and can detect negative-weight cycles, returning an appropriate error rather than a meaningless result. This makes Bellman-Ford the basis for the Routing Information Protocol (RIP) used in smaller IP networks.

All-Pairs Shortest Paths

When shortest paths between all pairs of vertices are needed simultaneously, algorithms such as Floyd-Warshall and Johnson's algorithm are employed. Floyd-Warshall runs in O(V³) time using dynamic programming and works for graphs with negative edges but no negative cycles. Johnson's algorithm applies a reweighting technique to eliminate negative edges, then runs Dijkstra's from every vertex, achieving O(V² log V + VE) time, which is faster than Floyd-Warshall on sparse graphs. Research published in the Journal of the ACM on all-pairs shortest paths established that the problem can be solved in O(V²) time with high probability using randomized techniques, narrowing the gap with the trivially established lower bound. Parallel implementations targeting GPU clusters, studied in IEEE publications on efficient parallel shortest path computation, extend these algorithms to graphs with millions of vertices.

Applications

The shortest path problem has applications in a wide range of fields, including:

  • IP network routing protocols such as OSPF and IS-IS, which compute shortest paths using Dijkstra's algorithm
  • GPS and mapping systems for real-time route guidance in road networks
  • Airline and rail network optimization for timetable and connection planning
  • Robotic motion planning in configuration spaces represented as graphs
  • Bioinformatics sequence alignment and protein interaction network analysis
Loading…