retagged by
908 views
0 votes
0 votes

In a given following graph among the following sequences:

 

  1. abeghf 
  2. abfehg
  3. abfhge
  4. afghbe 

Which are depth first traversals of the above graph?

  1. I,II and IV only
  2. I and IV only
  3. II,III and IV only
  4. I,III and IV only
retagged by

1 Answer

0 votes
0 votes

The DFS algorithm is a recursive algorithm that uses the idea of backtracking. It involves exhaustive searches of all the nodes by going ahead, if possible, else by backtracking.

Here, the word backtrack means that when you are moving forward and there are no more nodes along the current path, you move backwards on the same path to find nodes to traverse. All the nodes will be visited on the current path till all the unvisited nodes have been traversed after which the next path will be selected.

This recursive nature of DFS can be implemented using stacks. The basic idea is as follows:
Pick a starting node and push all its adjacent nodes into a stack.
Pop a node from stack to select the next node to visit and push all its adjacent nodes into a stack.
Repeat this process until the stack is empty. However, ensure that the nodes that are visited are marked. This will prevent you from visiting the same node more than once. If you do not mark the nodes that are visited and you visit the same node more than once, you may end up in an infinite loop.

https://www.hackerearth.com/practice/algorithms/graphs/depth-first-search/tutorial/

https://gateoverflow.in/911/gate2003-21

Answer:

Related questions

0 votes
0 votes
1 answer
1
admin asked Mar 30, 2020
9,944 views
Given an undirected graph $G$ with $V$ vertices and $E$ edges, the sum of the degrees of all vertices is$E$$2E$$V$$2V$
0 votes
0 votes
1 answer
3
admin asked Mar 30, 2020
2,075 views
A path in graph $G$, which contains every vertex of $G$ and only once?Euler circuitHamiltonian pathEuler PathHamiltonian Circuit
1 votes
1 votes
1 answer
4
admin asked Mar 30, 2020
972 views
Considering the following graph, which one of the following set of edges represents all the bridges of the given graph?$(a,b), (e,f)$$(a,b), (a,c)$$(c,d), (d,h)$$(a,b)$