I am looking at the DFS pseudocode here
dfs(node start) {
stack s;
s.push(start);
while (s.empty() == false) {
top = s.top();
s.pop();
mark top as visited;
check for termination condition
add all of top's unvisited neighbors to the stack.
mark top as not visited;
}
}
dfs(node current) {
mark current as visited;
visit all of current's unvisited neighbors by calling dfs(neighbor)
mark current as not visited;
}
Why is the author marking a vertex as not visited after visiting all its neighbours? Is that a required step here. Since we are just searching for a vertex, should it not work with out marking the vertex as not visited?
Another link here does not in fact mark the vertex as not visited after setting it as visited.