easyTreeTrees

Symmetric Tree

easyTime: O(n)Space: O(h)

Recognize the pattern

mirror image checkcompare left with rightstructural equality

Brute force idea

The naive version of Symmetric Tree sounds like this: Generate both subtrees as arrays and compare — but wasteful. That direct path helps you understand the question, but it tends to treat every possibility as brand new instead of learning from earlier steps.

Better approach

A calmer way to see Symmetric Tree is this: Recursive comparison: left.left matches right.right, and left.right matches right.left. The goal is not to be clever for its own sake, but to remember the one relationship that keeps the solution grounded as you move forward.

Key invariant

The truth you want to protect throughout Symmetric Tree is this: Two subtrees are mirrors if outer children match and inner children match. If that remains true after every update, the rest of the reasoning has a stable place to stand.

Watch out for

The trap in Symmetric Tree usually looks like this: Only checking values without checking structure — both values AND structure must mirror. When the code becomes mechanical before the idea is clear, small edge cases start breaking the whole story.

Trees Pattern