31 - Data Structure - Breadth First Traversal
31 - Data Structure - Breadth First Traversal
Traversal
Rule 1 − Visit the adjacent unvisited vertex. Mark it as visited. Display it.
Insert it in a queue.
Rule 2 − If no adjacent vertex is found, remove the first vertex from the
queue.
We start from
2 visiting S (starting node),
and mark it as visited.
From A we have D as
unvisited adjacent node.
7
We mark it as visited and
enqueue it.
At this stage, we are left with no unmarked (unvisited) nodes. But as per the
algorithm we keep on dequeuing in order to get all unvisited nodes. When the
queue gets emptied, the program is over.