Graph Theory37 sections · 1633 units
Open in Course

Problem - Coin Game on DAG (Part 4)

(Linear time solution)

The time complexity is O(V+E)O(V + E). Topological sort takes O(V+E)O(V + E), and processing vertices takes O(V+E)O(V + E) total because you check each edge once.

The space complexity is O(V)O(V) for the boolean array and O(V+E)O(V + E) for the graph representation. This is efficient. Even for large DAGs, this algorithm runs quickly. You process each vertex and each edge exactly once, making this optimal for the problem.