<p>Try searching for "k shortest paths". There are different answers depending on whether your graph is directed or undirected, whether you allow repeated vertices in your paths, etc.</p>

CC BY-SA 3.0
2014-05-03T07:37:47.390Z
2014-05-03T07:37:47.390Z
David Eppstein
<p>Given a directed graph with $n$ vertices with non-negative edge weights, I would like to find first $n^2$, $s$-$t$ minpaths with minimum sum of non-negative weights. By using <a href="http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm" rel="nofollow">Dijkstras</a> shortest path algorithm I found out the first minpath. In order to get next minpath I have replaced edges in first minpath with infinity. By following this procedure I am missing out many minpaths whose sum of weights are much smaller than what I am getting by following above procedure.</p>

<p>Can some one suggest me a good procedure to list first $n^2$ minpaths. </p>

<p>Thank you.</p>

CC BY-SA 3.0
2014-05-03T08:47:37.607Z
Related: http://stackoverflow.com/questions/4971850/which-algorithm-can-i-use-to-find-the-next-to-shortest-path-in-a-graph
Tyson Williams
CC BY-SA 3.0
2014-05-03T11:44:29.937Z
One way is to remove edges from every possible suffix of shortest path and finding other paths. Doing same for all possible cases.  This is not an efficient way but it's a start point. Just consider that all possible suffixes of such paths are polynomialy bounded by graph size.
Saeed
CC BY-SA 3.0
2014-05-04T09:16:42.847Z
I think this has been answered (multiple times) on [cs.SE].
Raphael
<graph-algorithms>
Algorithm to find s-t min paths in a weighted graph
Kumar
# Algorithm to find s-t min paths in a weighted graph

(Asked by: username_0 on 2014-05-03)

Given a directed graph with $n$ vertices with non-negative edge weights, I would like to find first $n^2$, $s$-$t$ minpaths with minimum sum of non-negative weights. By using [Dijkstras](http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm) shortest path algorithm I found out the first minpath. In order to get next minpath I have replaced edges in first minpath with infinity. By following this procedure I am missing out many minpaths whose sum of weights are much smaller than what I am getting by following above procedure.

Can some one suggest me a good procedure to list first $n^2$ minpaths.

Thank you.

**Tags:** graph-algorithms

> **Comments:**
> **username_1**: Related: http://stackoverflow.com/questions/4971850/which-algorithm-can-i-use-to-find-the-next-to-shortest-path-in-a-graph  
> **username_2**: One way is to remove edges from every possible suffix of shortest path and finding other paths. Doing same for all possible cases.  This is not an efficient way but it's a start point. Just consider that all possible suffixes of such paths are polynomialy bounded by graph size.  
> **username_3**: I think this has been answered (multiple times) on [cs.SE].  

---

## 1 answers

### Answer by username_4 on 2014-05-03. Score: 5

Try searching for "k shortest paths". There are different answers depending on whether your graph is directed or undirected, whether you allow repeated vertices in your paths, etc.


---

