depth first searchdepth first search (dfsalgorithm traverses graph in depthward motion and uses stack to remember to get the next vertex to start searchwhen dead end occurs in any iteration as in the example given abovedfs algorithm traverses from to to to to to firstthen to and lastly to it employs the following rules rule visit the adjacent unvisited vertex mark it as visited display it push it in stack rule if no adjacent vertex is foundpop up vertex from the stack (it will pop up all the vertices from the stackwhich do not have adjacent vertices rule repeat rule and rule until the stack is empty step traversal description initialize the stack