in Algorithms recategorized by
726 views
3 votes
3 votes
Which of the following are true:-

1. DFS continues to visited first unvisited successor of each node as long as possible.

2. Certain nodes are pushed into the stack.

3. DFS first visits all the immediate successors of a node before moving to their successors

4. Certain nodes are pushed into the stack for nore than once.

The answer is 1,2,4.

But I think it should be 1,4.

As.

1. True -- It is DFS characteristic.

2. Doubt ful because in Recursive or iterative all nodes are pushed into the stack.

3. False -- this happens in BFS not in DFS.

4. True -- Iterative DFS.
in Algorithms recategorized by
726 views

4 Comments

@SHUBHAM SHASTRI

@joshi_nitish,

​​​​​​​can you provide my algorithm, where some nodes are not pushed into the stack.

Because in recursive we have to push each and every node into the stack, and in iterative it is sometime we have to push a node more than once, but here also every node will go into the stack.

0
0
can u please provide some example where nodes are visited ore than once because i think whenwe perform dfs we mark node visited abd if node is visited we never push into stack.

and i think all nodes should be push into stack unless graph is disconnected.

please tell me where i am wrong.
0
0
So, you mean to say that when the graph is disconnected then there are some nodes which never pushed into the stack??
0
0

Please log in or register to answer this question.

Related questions