BFS traversal of directed graph from a given node
- by p1
Hi,
My understanding of basic BFS traversal for a graph is:
BFS
{
Start from any node . Add it to que. Add it to visited array
While(que is not empty)
{
remove head from queue. Print node;
add all unvisited direct subchilds to que; mark them as visited
}
}
However, if we have to traverse a DIRECTED graph from a given node and not all nodes are accessible from the given node [directly or indirectly] how do we use BFS for the same.
Can you please explain in this graph as well:
a= b = d = e = d
a= c = d
Here if the starting node is b , we never print a and c.
Am I missing something in the algorithm.
P.S: I used "HashMap adj = new HashMap();" to create the adjacencey list to store graph
Any pointers are greatly appreciated.
Thanks.