DSA SectionMedium

Symmetric Tree

Detailed guide and Python implementation for the 'Symmetric Tree' problem.

Problem Statement

Medium

Write a function is_symmetric(tree_arr) that takes an array representation of a binary tree tree_arr and checks if the tree is symmetric (a mirror of itself around the center, matching both structure and values).

Constraints
  • 0 <= len(tree_arr) <= 1000

Examples

Example 1
Input
tree_arr = [1, 2, 2, 3, 4, 4, 3]
Output
True
Explanation

The tree is symmetric in both shape and node values.

Example 2
Input
tree_arr = [1, 2, 2, None, 3, None, 3]
Output
False
Explanation

Left child 2 has right child 3, right child 2 has right child 3. Values match but structures are not mirrors.

Need a Hint?
Consider using Trees-specific data structures like sets or heaps.
Edge Cases to Watch
  • Empty input structures
  • Single element inputs
  • Large numerical bounds

Ready to Solve?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Open in Editor

Recommended Python Resources

Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.