C Program to implement BFS Algorithm for Connected Graph

By | May 20, 2017

BFS Algorithm for Connected Graph


Write a C Program to implement BFS Algorithm for Connected Graph. Here’s simple Program for traversing a directed graph through Breadth First Search(BFS),  visiting only those vertices that are reachable from start vertex.


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 for Creation of Adjacency Matrix

Below is the source code for C Program to implement BFS Algorithm for Connected Graph 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 : :

2 thoughts on “C Program to implement BFS Algorithm for Connected Graph

  1. Pingback: C Program to implement BFS Algorithm for Disconnected Graph

  2. Pingback: C Program to implement DFS Algorithm for Connected Graph

Leave a Reply

Your email address will not be published. Required fields are marked *