Theoretical Computer Science Stack Exchange is a question and answer site for theoretical computer scientists and researchers in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 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.

share|cite|improve this question
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 May 3 '14 at 11:44
I think this has been answered (multiple times) on Computer Science. – Raphael May 4 '14 at 9:16

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.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.