What will be the time complexity of the iterative depth first traversal code(V=no. of vertices E=no.of edges)?

Duyên Trương

New member
What will be the time complexity of the iterative depth first traversal code(V=no. of vertices E=no.of edges)?
A. O(V+E)
B. O(V)
C. O(E)
D. O(V*E)
 
Answer: A
Explanation: As the time required to traverse a full graph is V+E so its worst case time complexity becomes O(V+E). The time complexity of iterative and recursive DFS are same.
 

Tìm kiếm

Back
Top