k shortest path routing

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search

The k shortest path routing algorithm is an extension algorithm of the shortest path routing algorithm in a given network.

It is sometimes crucial to have more than one path between two nodes in a given network. In the event there are additional constraints, other paths different from the shortest path can be computed. To find the shortest path one can use shortest path algorithms such as Dijkstra’s algorithm or Bellman Ford algorithm and extend them to find more than one path. The k shortest path routing algorithm is a generalization of the shortest path problem. The algorithm not only finds the shortest path, but also k − 1 other paths in non-decreasing order of cost. k is the number of shortest paths to find. The problem can be restricted to have the k shortest path without loops (loopless k shortest path) or with loop.


Since 1957 there have been many papers published on the k shortest path routing algorithm problem. Most of the fundamental works on not just finding the single shortest path between a pair of nodes, but instead listing a sequence of the k shortest paths, were done between the 1960s and up to 2001. Since then, most of the recent research has been about the applications of the algorithm and its variants. In 2010, Michael Gunter et al. published a book on Symbolic calculation of k-shortest paths and related measures with the stochastic process algebra tool CASPA.[1]

Important works on the k shortest paths problem:

Year of Publication Author Title
1971 Jin Y. Yen Finding the k Shortest Loopless Paths in a Network
1972 M. T. Ardon et al. A recursive algorithm for generating circuits and related subgraphs
1973 P. M. Camerini et al. The k shortest spanning trees of a graph
1975 K. Aihara An approach to enumerating elementary paths and cutsets by Gaussian elimination method
1976 T. D. Am et al. An algorithm for generating all the paths between two vertices in a digraph and its application
1988 Ravindra K. Ahuja et al. Faster algorithms for the shortest path problem
1989 S. Anily et al. Ranking the best binary trees
1990 Ravindra K. Ahuja et al. Faster algorithms for the shortest path problem
1993 El-Amin et al. An expert system for transmission line route selection
1997 David Eppstein Finding the k Shortest Paths
1997 Ingo Althofer On the k-best mode in computer chess: measuring the similarity of move proposals
1999 Ingo Althofer Decision Support Systems With Multiple Choice Structure
2011 Husain Aljazzar, Stefan Leue K*: A heuristic search algorithm for finding the k shortest paths

The BibTeX database contains more articles.


The Dijkstra algorithm can be generalized to find the k shortest paths.

  • G(V, E): weighted directed graph, with set of vertices V and set of directed edges E,
  • w(u, v): cost of directed edge from node u to node v (costs are non-negative).
Links that do not satisfy constraints on the shortest path are removed from the graph
  • s: the source node
  • t: the destination node
  • K: the number of shortest paths to find
  • Pu: a path from s to u
  • B is a heap data structure containing paths
  • P: set of shortest paths from s to t
  • countu: number of shortest paths found to node u


P =empty,
countu = 0, for all u in V
insert path Ps = {s} into B with cost 0
while B is not empty and countt < K:
– let Pu be the shortest cost path in B with cost C
B = B{Pu }, countu = countu + 1
– if u = t then P = P U Pu
– if countuK then
  • for each vertex v adjacent to u:
– if v is not in Pu then
– let Pv be a new path with cost C + w(u, v) formed by concatenating edge (u, v) to path Pu
– insert Pv into B
return P


There are two main variations of the k shortest path routing algorithm. Other variations only fall in between these.

  • In the first variation, loops are allowed, that is paths are allowed to revisit the same node multiple times. The following papers deal with this variation.[2]
  • The second variation deals with simple paths. It is also called loopless k shortest path routing problem and is attributed to J. Y. Yen [3]

First variant[edit]

In the first variant, the paths are not required to be loopless (this is the simple one): David Eppstein's algorithm achieves the best running time complexity[dubious ].[2]

Second variant[edit]

In the second variant, attributed to Jin Y. Yen, the paths are required to be loopless.[3] (This restriction introduced another level of complexity.) Yen's algorithm is used where only simple paths are considered, whereas Eppstein's algorithm is used when non-simple paths are allowed (e.g., paths are allowed to revisit the same node multiple times) or where loops are not possible (in directed acyclic graphs).

Paths are not required to be loopless[edit]

In all that follows, m is the number of edges and n is the number of vertices.

Eppstein's algorithm provides the best results[clarification needed].[2] Eppstein's model finds the k shortest paths (allowing cycles) connecting a given pair of vertices in a digraph, in time O(m + n log nk). This algorithm uses a graph transformation technique.

This model can also find the k shortest paths from a given source s to each vertex in the graph, in total time O(m + n log n + kn).

Loopless k shortest path routing algorithm[edit]

The best running time for this model is attributed to Jin. Y. Yen.[3] Yen's algorithm finds the lengths of all shortest paths from a fixed node to all other nodes in an n-node non negative-distance network. This technique only requires 2n2 additions and n2 comparisons – which is less than other available algorithms require.

The running time complexity is O(kn(m + n log n)), which is pseudo-polynomial. m represents the number of edges and n is the number of vertices.

Some examples and description[edit]

Example #1[edit]

The following example makes use of Yen’s model to find the first k shortest paths between communicating end nodes. That is, it finds the first, second, third, etc. up to the Kth shortest path. More details can be found here. The code provided in this example attempts to solve the k shortest path routing problem for a 15-nodes network containing a combination of unidirectional and bidirectional links:

15-node network containing a combination of bi-directional and uni-directional links

Example #2[edit]

Another example is the use of k shortest paths algorithm to track multiple objects. The technique implements a multiple object tracker based on the k shortest paths routing algorithm. A set of probabilistic occupancy maps is used as input. An object detector provides the input.

The complete details can be found at "Computer Vision Laboratory – CVLAB" .

Example #3[edit]

Another use of k shortest paths algorithms is to design a transit network that enhances passengers' experience in public transportation systems. Such an example of a transit network can be constructed by putting traveling time under consideration. In addition to traveling time, other conditions may be taken depending upon economical and geographical limitations. Despite variations in parameters, the k shortest path algorithms finds the most optimal solutions that satisfies almost all user needs. Such applications of k shortest path algorithms are becoming common, recently Xu, He, Song, and Chaudry (2012) studied the k shortest path problems in transit network systems. [4]


The k shortest path routing is a good alternative for:

Related problems[edit]

Cherkassky et al.[5] provide more algorithms and associated evaluations.

See also[edit]


  1. ^ Michael Günther et al.: “Symbolic calculation of k-shortest paths and related measures with the stochastic process algebra tool CASPA”. In: Int’l Workshop on Dynamic Aspects in Dependability Models for Fault-Tolerant Systems (DYADEM-FTS), ACM Press (2010) 13–18.
  2. ^ a b c Eppstein, D. (1998). "Finding the k shortest paths". SIAM J. Comput. 28 (2): 652–673. CiteSeerX doi:10.1137/S0097539795290477.
  3. ^ a b c Yen, J. Y (1971), "Finding the k-Shortest Loopless Paths in a Network", Management Science, 17 (11): 712–716, doi:10.1287/mnsc.17.11.712.
  4. ^ Xu, W., He, S., Song, R., & Chaudhry, S. (2012). Finding the k shortest paths in a schedule-based transit network. Computers & Operations Research, 39(8), 1812-1826. doi:10.1016/j.cor.2010.02.005
  5. ^ Cherkassky, Boris V.; Goldberg, Andrew V.; Radzik, Tomasz (1996). "Shortest paths algorithms: theory and experimental evaluation". Mathematical Programming. Ser. A 73 (2): 129–174.

External links[edit]