I am nt getting wat u said ... u hav solved it without using stack ???

5,868 views

## 4 Answers

Best answer

For GATE purpose, without actually applying DFS, we can answer by just seeing options.

In DFS, we go in depth first i.e., one node to another in depth first order.

Here, $abfehg$ is not possible as we can not go from $f$ to $e$ directly.

Thus, option $(D)$ is correct.

In all the other options we can reach directly from the node to the next node.

So, just visualize and do.

In DFS, we go in depth first i.e., one node to another in depth first order.

Here, $abfehg$ is not possible as we can not go from $f$ to $e$ directly.

Thus, option $(D)$ is correct.

In all the other options we can reach directly from the node to the next node.

So, just visualize and do.

### 5 Comments

keep moving from the root vertex like- moving from root to any of the child node, then from the child node to any of its child node and backtrack only when u have exhausted all the child nodes of the current node, in this manner if u can visit all the nodes its a successful DFS. If in the option like option b here, you happen to backtrack before exhausting all the child nodes of the current node, it is not a successful DFS.

Answer will be (D)

DFS goes upto how much depth possible and then backtrack and go to the next link.

Here only 'abf**eh**g' not possible because e and h consecutively is not possible by any backtracking of DFS traversal

### 8 Comments

@srestha mam, using stack i am getting only 4th one as valid depth first traversal. Because, an elemant is first popped out and then its adjacent elements are pushed onto stack. Can you please show using stack how 1 and 3 are also possible?