# How to find more than 1 successive shortest paths between two vertices in unweighted and undirected graph using BFS?

I have tried to find and print more than one successive shortest paths between two vertices in the undirected graph. Using BFS as DFS will not be optimal in this case, as it can go deep into the stack.

Wrote this function but not getting the correct response and also tried to find help over StackOverflow and other platforms but did not find a solution for undirected graph.

• Is the graph weighted? – Steven Apr 13 at 20:46
• en.wikipedia.org/wiki/K_shortest_path_routing – D.W. Apr 13 at 21:07
• Coding questions are off-topic here. Not everyone here knows C++. Please edit the question to replace the code with concise pseudocode. – D.W. Apr 13 at 21:08
• @D.W. It'm not sure that the question is about finding $k$ successive shortest paths in a graph (which might have different lengths). It seems to me that the goal is to find $k$ distinct paths from $s$ to $t$, all of which are shortest. It might be worth to clarify this in the question. Clearly a solution for the first problem implies a solution for the second problem (but not vice-versa). – Steven Apr 13 at 21:17
• @Steven, hmm, if it's unclear, perhaps this should be put on hold until that is cleared up. Is there a difference? If there are $k$ distinct paths all tied for shortest, then using an algorithm for finding the $k$ shortest paths will find all of them. If there aren't, that will also be apparent after running an algorithm to find the $k$ shortest paths. – D.W. Apr 13 at 21:20