C Program to implement DFS Algorithm for Connected Graph

By | 09.06.2017

DFS Algorithm for Connected Graph

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

Depth First Search (DFS)

Depth First Search (DFS) algorithm traverses a graph in a depthward motion and uses a stack to remember to get the next vertex to start a search, when a dead end occurs in any iteration.

It employs the following rules.

  • Rule 1 − Visit the adjacent unvisited vertex. Mark it as visited. Display it. Push it in a stack.
  • Rule 2 − If no adjacent vertex is found, pop up a vertex from the stack. (It will pop up all the vertices from the stack, which do not have adjacent vertices.)
  • Rule 3 − Repeat Rule 1 and Rule 2 until the stack is empty.

We shall not see the implementation of Depth First Traversal (or Depth First Search) in C programming language

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

Below is the source code for C Program to implement DFS Algorithm for Connected Graph which is successfully compiled and run on Windows System to produce desired output as shown below :



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 : :

0 0 vote
Article Rating
Notify of
Inline Feedbacks
View all comments