← Tree Recursion

Pattern Recognition Drill

#37 — Inorder traversal

Easy Trees

The Problem

Return the inorder traversal of a binary tree as a list.

What approach would you use?

Think about it before scrolling down.

Key Signals

Tree Recursion

Recurse left, append current, recurse right. O(n) time.

Alt: Stack

Iterative with explicit stack: push lefts, pop and visit, go right. Same O(n).

Common Trap

Know all three traversals (in/pre/post) and when each is useful. Inorder = sorted for BSTs.

← #36 #38 →