edited by
324 views

1 Answer

0 votes
0 votes

Statement 1 and 3 will be true.

We push an element into call stack, when we visit a node, i.e. a node is reachable from a vertex (at start, this vertex will be source node). We pop an element from call stack, when all its children are visited. Hence, (node from where it is called) is the last one to get popped off.

Since, both v1 and v2 are present simultaneously, that means both vertex can be visited from node s (since s will be in bottom of stack, and v1 and v2 will be above them in some order). So, statement 1 is true because path is asked.

Now, either v1 is above v2 or v2 is above v1 in the stack, that means either v1 is child of v2 or v2 is child of v1. So, statement 3 is true. Statement 2 is contradictory to this, hence it is false.

Refer : http://www.egr.unlv.edu/~larmore/Courses/CSC477/bfsDfs.pdf

Related questions

2 votes
2 votes
2 answers
1
sumit chakraborty asked Jan 11, 2018
1,297 views
If DFS algorithm applied starting from vertex ‘A’ which uses stack data structure then the height of stack is needed in worst case for DFS traversal is _________.