Trees
TimeO(n)SpaceO(h)
Walk every node of a tree. Switch the traversal order (in / pre / post / level) to see how the visit sequence changes — the recursion is tracked on the call stack.
Key idea. Every traversal visits all n nodes; the order (in/pre/post/level) decides the sequence. Recursion's depth is the tree height h.
1
Loading…
—