I understand how BFS can give the shortest path in a graph but I am not able to code the entire thing. The part where I am stuck is when I pop a node from the queue and see that its the target node, how do I trace back the complete path of nodes that led to the target? In simple BFS we only have a queue but I think in this case we need some other data structure as well to keep track of path? What would be the efficient way to do that? Thank you!
closed as unclear what you're asking by David Richerby, Yuval Filmus, Evil, Rick Decker, Juho Mar 28 '17 at 13:19
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.