This is similar to How to trace the path in a Breadth-First Search?, but the method described in the answers in that post doesn't work for my case, it seems.
By path here, I essentially mean a sequence of connected nodes to get from a beginning to end state.
Consider an undirected graph with vertices V={a,b,c} and edges = {{a,b},{a,c}}, and assume that we must traverse the successors alphabetically. We start at node a
and the end state is to visit all 3 nodes.
Breadth first search would first visit the edge a->b
, and then the edge a->c
. So the solution path is a->b->a->c
. Since there is no edge between b
& c
, we must go back through a
(so we must traverse the edge b->a
). In the answer in the above linked post, the accepted solution would only output a->c
.
I can't think of a way to modify the conventional bfs algorithm to do this. I have the same question for dfs, but I'd like to start with bfs for now.