DFS algorithms by R4R Team

DFS:
-Stands for "Depth first search"
-This algorithms are used to traverse a graph in a depthward motion and uses a stack remember to get the next vertex to start a search, when a dead end occurs in any iteration.

Which data structure use to implement DFS ?
"Stack" is used to implement this.

Steps:

Step1:
visit the adjacent unvisited vertex. Mark it as visited. Display it. Push it in a stack.

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

Step3:
Repeat Step1 and step2 until the stack is empty.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!