Redirected
retagged by
1,280 views
2 votes
2 votes

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 _________.

retagged by

2 Answers

Best answer
2 votes
2 votes

In worst case of DFS

Starting from "A"

Push A

Push  D

Push E

Push  G

Push F

Push  I

Push B  and now backtrack 

therefore 7 is height of stack Please note multiple sequences of worst case also possible one of them is traversing ADEGFIB

selected by
0 votes
0 votes

maximum height of stack =6

Related questions