in Graph Theory retagged by
883 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
in Graph Theory retagged by
by
883 views

1 comment

ans is D ..for DFS we need to explore neighbours in LIFO sequence . so if start with a  next can be either b, e or f  but after f we can not take  e  so II is not possible. we need to expand neighbours of f
1
1

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

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true