I am trying to write some BFS algorithm in Java and read online that we should maintain something like an array prev
where prev[i] = j
indicates that the node we visited before i
was node j
.
So suppose I have such an array. How do I recover the original path? Is there any sample codes I can look at for this? I don't really get the explanation in the solution it seems to just gloss over the steps in 'getting back' to the source.