Uit Wikibooks
Naar navigatie springen Naar zoeken springen

Kopie en.wikipedia (:

A graph with 6 vertices and 7 edges

In graph theory, the shortest path problem is the problem of finding a path between two vertices (or nodes) in a graph such that the sum of the weights of its constituent edges is minimized. An example is finding the quickest way to get from one location to another on a road map; in this case, the vertices represent locations and the edges represent segments of road and are weighted by the time needed to travel that segment.

There are several variations according to whether the given graph is undirected, directed, or mixed. For undirected graphs, the shortest path problem can be formally defined as follows. Given a weighted graph (that is, a set V of vertices, a set E of edges, and a real-valued weight function f : E → R), and elements v and v' of V, find a path P (a sequence of edges) from v to a v' of V so that

is minimal among all paths connecting v to v' .

The problem is also sometimes called the single-pair shortest path problem, to distinguish it from the following variations:

  • The single-source shortest path problem, in which we have to find shortest paths from a source vertex v to all other vertices in the graph.
  • The single-destination shortest path problem, in which we have to find shortest paths from all vertices in the directed graph to a single destination vertex v. This can be reduced to the single-source shortest path problem by reversing the arcs in the directed graph.
  • The all-pairs shortest path problem, in which we have to find shortest paths between every pair of vertices v, v' in the graph.

These generalizations have significantly more efficient algorithms than the simplistic approach of running a single-pair shortest path algorithm on all relevant pairs of vertices.


The most important algorithms for solving this problem are:

Additional algorithms and associated evaluations may be found in Cherkassky et al.[1]


A roadnetwork can be considered as a graph with positive weights. The nodes represent road junctions and each edge of the graph is associated with a road segment between two junctions. The weight of an edge may correspond to the length of the associated road segment, the time needed to traverse the segment or the cost of traversing the segment. Using directed edges it is also possible to model one-way streets. Such graphs are special in the sense that some edges are more important than others for long distance travel (i.e. highways). This property has been formalized using the notion of highway dimension. ( There are a great number of algorithms that exploit this property and are therefore able to compute the shortest path a lot quicker than would be possible on general graphs.

All of these algorithms work in two phases. In the first phase, the graph is preprocessed without knowing the source or target node. This phase may take several days for realistic data and some techniques. The second phase is the query phase. In this phase, source and target node are known. The running time of the second phase is generally less than a second. The idea is that the road network is static, so the preprocessing phase can be done once and used for a large number of queries on the same road network.

The algorithm with the fastest known query time is called hub labeling and is able to compute shortest path on the road networks of Europe or the USA in a fraction of a microsecond. ( Other techniques that have been used are:

Single-source shortest paths[bewerken]

Directed acyclic graphs[bewerken]

Directed graphs with nonnegative weights[bewerken]

Algorithm Time complexity Author
O(V4) Sjabloon:Harvnb
O(V2EL) Sjabloon:Harvnb
Bellman–Ford algorithm O(VE) Sjabloon:Harvnb, Sjabloon:Harvnb
O(V2 log V) Sjabloon:Harvnb, Sjabloon:Harvnb, Minty (cf. Sjabloon:Harvnb), Sjabloon:Harvnb
Dijkstra's algorithm O(V2) Sjabloon:Harvnb, Sjabloon:Harvnb
... ... ...
Dijkstra's algorithm with Fibonacci heaps O(E + V log V) Sjabloon:Harvnb, Sjabloon:Harvnb
O(E log log L) Sjabloon:Harvnb, Sjabloon:Harvnb
Gabow's algorithm O(E logE/V L) Sjabloon:Harvnb, Sjabloon:Harvnb
O(E + V√log L) Sjabloon:Harvnb

Sjabloon:Incomplete list

Planar directed graphs with nonnegative weights[bewerken]

Directed graphs with arbitrary weights[bewerken]

Planar directed graphs with arbitrary weights[bewerken]

All-pairs shortest paths[bewerken]

Floyd–Warshall algorithm

Directed graphs with unit weights[bewerken]

Undirected graphs with unit weights[bewerken]

Directed graphs with nonnegative weights[bewerken]

Planar directed graphs with nonnegative weights[bewerken]

Directed graphs with arbitrary weights[bewerken]

Planar directed graphs with arbitrary weights[bewerken]


Shortest path algorithms are applied to automatically find directions between physical locations, such as driving directions on web mapping websites like Mapquest or Google Maps. For this application fast specialized algorithms are available.[2]

If one represents a nondeterministic abstract machine as a graph where vertices describe states and edges describe possible transitions, shortest path algorithms can be used to find an optimal sequence of choices to reach a certain goal state, or to establish lower bounds on the time needed to reach a given state. For example, if vertices represents the states of a puzzle like a Rubik's Cube and each directed edge corresponds to a single move or turn, shortest path algorithms can be used to find a solution that uses the minimum possible number of moves.

In a networking or telecommunications mindset, this shortest path problem is sometimes called the min-delay path problem and usually tied with a widest path problem. For example, the algorithm may seek the shortest (min-delay) widest path, or widest shortest (min-delay) path.

A more lighthearted application is the games of "six degrees of separation" that try to find the shortest path in graphs like movie stars appearing in the same film.

Other applications include "operations research, plant and facility layout, robotics, transportation, and VLSI design".[3]

Related problems[bewerken]

For shortest path problems in computational geometry, see Euclidean shortest path.

The travelling salesman problem is the problem of finding the shortest path that goes through every vertex exactly once, and returns to the start. Unlike the shortest path problem, which can be solved in polynomial time in graphs without negative cycles (edges with negative weights), the travelling salesman problem is NP-complete and, as such, is believed not to be efficiently solvable (see P = NP problem). The problem of finding the longest path in a graph is also NP-complete.

The Canadian traveller problem and the stochastic shortest path problem are generalizations where either the graph isn't completely known to the mover, changes over time, or where actions (traversals) are probabilistic.

The shortest multiple disconnected path [4] is a representation of the primitive path network within the framework of Reptation theory.

The problems of recalculation of shortest paths arises if some graph transformations (e.g., shrinkage of nodes) are made with a graph.[5]

The widest path problem seeks a path so that the minimum label of any edge is as large as possible.

Linear programming formulation[bewerken]

There is a natural linear programming formulation for the shortest path problem, given below. It is very trivial compared to most other uses of linear programs in discrete optimization, however it illustrates connections to other concepts.

Given a directed graph (V, A) with source node s, target node t, and cost wij for each arc (i, j) in A, consider the program with variables xij

minimize subject to and for all i,

This LP, which is common fodder for operations research courses, has the special property that it is integral; more specifically, every basic optimal solution (when one exists) has all variables equal to 0 or 1, and the set of edges whose variables equal 1 form an s-t dipath. See Ahuja et al.[6] for one proof, although the origin of this approach dates back to mid-20th century.

The dual for this linear program is

maximize ytys subject to for all ij, yjyiwij

and feasible duals correspond to the concept of a consistent heuristic for the A* algorithm for shortest paths. For any feasible dual y the reduced costs are nonnegative and A* essentially runs Dijkstra's algorithm on these reduced costs.

See also[bewerken]


  1. Sjabloon:Cite journal.
  2. Sjabloon:Cite document.
  3. Sjabloon:Cite journal
  4. Sjabloon:Cite journal
  5. Ladyzhensky Y., Popoff Y. Algorithm to define the shortest paths between all nodes in a graph after compressing of two nodes. Proceedings of Donetsk national technical university, Computing and automation. Vol.107. Donetsk, 2006, pp. 68–75.Sjabloon:Verify source
  6. . {{{Titel}}} .

Further reading[bewerken]


Informatie afkomstig van Wikibooks NL.
Wikibooks NL is onderdeel van de wikimediafoundation.