What is the space complexity of standard DFS(V: no. of vertices E: no. of edges)?

What is the space complexity of standard DFS(V: no. of vertices E: no. of edges)?
A. O(V+E)
B. O(V)
C. O(E)
D. O(V*E)
 
Answer: B
Explanation: In the worst case the space complexity of DFS will be O(V) in the case when all the vertices are stored in stack. This space complexity is excluding the space required to store the graph.
 

Tìm kiếm

Back
Top