What is the time complexity of DFS for a graph represented using an adjacency list?

Options

  • A. O(V + E)
  • B. O(V^2)
  • C. O(log V)
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

A. O(V + E)

Detailed Explanation

Depth-First Search (DFS) takes O(V + E) time when the graph is represented using adjacency lists. Each vertex is visited at most once and every edge is examined during the traversal. DFS can be implemented recursively or iteratively with a stack. Its applications include cycle detection, connected components, topological sorting, and finding paths in graphs.