Check if Two Trees are Symmetric
📖 Scenario: Imagine you have two family trees represented as binary trees. You want to check if these two trees are mirror images of each other, meaning they are symmetric around their center.
🎯 Goal: Build a TypeScript program that creates two binary trees, sets a helper variable, writes a function to check if the two trees are symmetric, and finally prints the result.
📋 What You'll Learn
Create two binary trees using the TreeNode class with exact values
Create a helper variable called
result initialized to trueWrite a function called
isSymmetric that takes two TreeNode parameters and returns a booleanUse recursion inside
isSymmetric to check if the trees are symmetricPrint the final
result which is true if symmetric, otherwise false💡 Why This Matters
🌍 Real World
Checking if two trees are symmetric is useful in graphics, data organization, and comparing hierarchical data structures.
💼 Career
Understanding tree symmetry helps in coding interviews and software roles involving data structures and algorithms.
Progress0 / 4 steps