#101

Symmetric Tree

Easy Mirror recursion

  1. Read
  2. Understand
  3. Hints
  4. Approach
  5. Solution
  6. Solved

?The problem

Decide whether a binary tree is a mirror image of itself around its centre.

This is a short summary in our own words. Read the full statement and examples on LeetCode: open problem ↗

◎Understanding

Really asking: is the tree its own mirror image?

Why this works: compare the left subtree with the right subtree crosswise: outer with outer, inner with inner.

Example: 1 (2 (3, 4), 2 (4, 3))

2 = 2, outer 3 = 3, inner 4 = 4 → symmetric

✦Hints open one at a time

↗Approach

</>Solution (Java)

!Common mistake

Comparing a.left with b.left — that checks equality, not mirroring.

Solve on LeetCode ↗
Complexity
  • Time: O(n).
  • Space: O(h).
Topic: Binary Trees
🎬 Episodes 53–60: video coming soon