Tree Traversal
Tree traversal is the process of visiting each node in a tree data structure exactly once in a systematic way.
Depth First Search
144. Binary Tree Preorder Traversal
Preorder traversal visits nodes in the order: Root → Left → Right. This means we process the current node first, then recursively traverse the left subtree, followed by the right subtree.
94. Binary Tree Inorder Traversal
Inorder traversal visits nodes in the order: Left → Root → Right. For binary search trees, this produces values in ascending sorted order.
145. Binary Tree Postorder Traversal
Postorder traversal visits nodes in the order: Left → Right → Root. This is useful when you need to process children before their parent (e.g., deleting nodes, calculating directory sizes).
606. Construct String from Binary Tree
Serialize the tree in preorder with parentheses around each child subtree. The only subtlety: a node with a right child but no left child must still emit an empty () for the missing left, so the structure is unambiguous. Empty parentheses are otherwise omitted.
Breadth First Search
102. Binary Tree Level Order Traversal
Level order traversal visits nodes level by level from top to bottom, left to right. This is also known as Breadth-First Search (BFS) for trees.
107. Binary Tree Level Order Traversal II
103. Binary Tree Zigzag Level Order Traversal
Vertical Order Traversal
314. Binary Tree Vertical Order Traversal
Vertical order traversal groups nodes by their horizontal distance from the root. Root is at column 0, left children decrease column by 1, right children increase column by 1. Within each column, nodes appear from top to bottom.