Breadth First Search (BFS) algorithm traverses a graph in a breadth ward motion.
BFS algorithm uses Queue data structure.
BFS Algorithm:
START
Step 1 − Visit the starting vertex and mark it as visited.
Display it.
Set a pointer to the starting vertex.(Currently working Vertex.)
Step 2 − if( Currently working Vertex has adjacent unvisited vertex )
{
Visit the adjacent unvisited vertex and Mark it as visited.
Insert it in a queue. (enqueue)
Display it.
}
else{
Update the pointer to the first element of queue.
Remove the first element from queue. (dequeue)
}
(repeat rule 2 until the queue is empty)
END
If you have any doubts please comment.
Don't forget to Share and Subscribe.
Email: [email protected]
facebook: https://www.facebook.com/sourav.s.nag
Twitter: https://twitter.com/SRN9999