#94

Binary Tree Inorder Traversal

EasyTreeHas vizStackTreeDFS
Related studio

Problem

Given the root of a binary tree, return the inorder traversal of its nodes' values.

Example 1

Input: root = [1,null,2,3]

Output: [1,3,2]

Left → node → right order.

Example 2

Input: root = []

Output: []

Empty tree.

Example 3

Input: root = [1]

Output: [1]

Single node.

Constraints

  • The number of nodes in the tree is in the range [0, 100].
  • -100 <= Node.val <= 100
Loading visualization…

Explanation

Binary Tree Inorder Traversal is a Easy interview problem tagged [Stack, Tree, DFS]. The winning approach is typically **Tree**.

Intuition

Tree problems factor into identical subproblems on subtrees.

Approach

Recurse on left/right (DFS) or process level-by-level with a queue (BFS).

  1. Define base case (null).
  2. Ask what left/right return.
  3. Combine into the node answer.
  4. Watch stack depth on skewed trees.

Solution

Pattern-level skeleton only — not this problem’s exact answer. Adapt it to the statement.

Pattern templateTree

Edge cases

  • •Empty or single-element input
  • •Duplicates and ties
  • •Maximum constraints / overflow
  • •Disconnected or unreachable states (for graphs)

Complexity

Time: O(n)

Space: O(1)

Before coding, restate the problem, name the pattern (Tree), and write the invariant or DP state in one sentence.

Learn the topic

Got it?

Mark #94 Binary Tree Inorder Traversal as understood when the pattern clicks.