Question: 1 procedure DFS-iterative(G,v): 2 let S be a stack 3 S.push(v) 4 while S is not empty V S.pop() if v is not labeled as
1 procedure DFS-iterative(G,v): 2 let S be a stack 3 S.push(v) 4 while S is not empty V S.pop() if v is not labeled as discovered: label v as discovered for all edges from v to w in G.adjacentEdges(v) do S.push(w) Figure 2 Depth First Search DFS (Method 1) s stack s.push(initial node) add initial node to visited while s is not empty: V s.peek() if for all E(v,u) there is one unvisited u: mark u as visited s.push(u) else s.pop Figure 3 Depth First Search (Method 2)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
