How to Check if a Binary Tree is Symmetric with Recursion

🚀 Day 114 of #LeetCode Challenge! Problem: Symmetric Tree 🌳 Concept: Check whether a binary tree is a mirror of itself (i.e., symmetric around its center). 💡 My Approach: Use recursion to compare left and right subtrees. A tree is symmetric if: Left subtree of left node matches right subtree of right node Right subtree of left node matches left subtree of right node Base cases: Both nodes NULL → symmetric ✅ One NULL and one not → not symmetric ❌ Values must match ✨ Example: Input: [1,2,2,3,4,4,3] Output: true ⏱ Time Complexity: O(N) — visiting all nodes 📦 Space Complexity: O(H) — recursion stack (H = height of tree) 📌 Key Insight: This is a classic mirror check — left's left must mirror right's right! 👨💻 GitHub Link: https://lnkd.in/grXFRA2i #LeetCode #BinaryTree #Recursion #SymmetricTree #MirrorTree #DSA #ProblemSolving #C++ #CodingChallenge #Day114

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories