0% found this document useful (0 votes)
12 views5 pages

Breath First Traversal

The Breadth First Search (BFS) algorithm traverses a graph using a queue to explore vertices in a breadthward motion. It follows specific rules to visit adjacent unvisited vertices, mark them, and manage the queue until all vertices are visited. The process concludes when the queue is empty, indicating that all nodes have been explored.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views5 pages

Breath First Traversal

The Breadth First Search (BFS) algorithm traverses a graph using a queue to explore vertices in a breadthward motion. It follows specific rules to visit adjacent unvisited vertices, mark them, and manage the queue until all vertices are visited. The process concludes when the queue is empty, indicating that all nodes have been explored.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Data Structure -

Breadth First
Traversal
 Breadth First Search (BFS) algorithm traverses a graph in a breadth ward
motion and uses a queue to remember to get the next vertex to start a search,
when a dead end occurs in any iteration.

 As in the example given above, BFS algorithm traverses from A to B to E to F


first then to C and G lastly to D. It employs the following rules.
 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.
 Rule 3 − Repeat Rule 1 and Rule 2 until the queue is empty.
 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.

You might also like