Graph Theory37 sections · 1633 units
Open in Course

Time and Space Complexity

Efficiency analysis.

Time complexity: O(V+E)O(V + E)

  • Checking conditions: O(V)O(V) to count degrees
  • Hierholzer's algorithm: O(E)O(E) since each edge is processed once
  • Total: O(V+E)O(V + E)

Space complexity: O(V+E)O(V + E)

  • Adjacency list: O(V+E)O(V + E)
  • Stack: O(V)O(V) in the worst case
  • Result path: O(E)O(E)

For dense graphs where E=O(V2)E = O(V^2), this becomes O(V2)O(V^2).

Hierholzer's algorithm is optimal since you must read all edges.