Graph Theory37 sections · 1633 units
Open in Course

Problem - Game on Tree (Part 3)

(Implementation)

The time complexity is O(n)O(n) where nn is the number of vertices. You visit each vertex once and check all its children.

The space complexity is O(n)O(n) for the recursion stack and O(n)O(n) for storing outcomes. Trees are great for practicing game theory because the structure is simple and you do not need to worry about cycles. The DFS naturally processes nodes in the right order for backward induction.