Pattern Recognition Drill
Easy Trees
The Problem
Return the preorder traversal of a binary tree as a list.
What approach would you use?
Think about it before scrolling down.
Append current, recurse left, recurse right. O(n) time.
Iterative: push root, pop and visit, push right then left (so left is processed first).
Common Trap
In iterative version, push right before left — stack is LIFO so left gets processed first.