C Program for Traversing Undirected Graph through DFS and classifying edges as tree edges and back edges

By | June 29, 2017

Traversing Undirected Graph through DFS and classifying edges as tree edges and back edges


Write a C Program for Traversing Undirected Graph through DFS and classifying edges as tree edges and back edges. Here’s simple Program for Traversing Undirected Graph through DFS and classifying edges as tree edges and back edges in C Programming Language.


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 for Traversing Directed Graph through DFS and classifying all edges

Below is the source code for C Program for Traversing Undirected Graph through DFS and classifying edges as tree edges and back edges in output 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