C Program for Traversing an Undirected Graph through BFS

By | May 26, 2017

Traversing an Undirected Graph through BFS


Write a C Program for Traversing an Undirected Graph through BFS. Here’s simple C Program for Traversing an Undirected Graph through Breadth First Search(BFS).


Breadth First Search (BFS)


BFS is a traversing algorithm where you should start traversing from a selected node (source or starting node) and traverse the graph layerwise thus exploring the neighbour nodes (nodes which are directly connected to source node). You must then move towards the next-level neighbour nodes.

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.

Also Read : : C Program to implement BFS Algorithm for Disconnected Graph

Below is the source code for C Program for Traversing an Undirected Graph through BFS which is successfully compiled and run on Windows System to produce desired output as shown below :


SOURCE CODE : :



OUTPUT : :



If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach up to you in short interval.


Thanks for reading the post…


Recommended Posts : :

Leave a Reply