Check if Two Trees are Symmetric
📖 Scenario: Imagine you have two family trees represented as simple binary trees. You want to check if these two trees are mirror images of each other, meaning they are symmetric in structure and values.
🎯 Goal: Build a program that creates two binary trees, sets up a helper function to check symmetry, and then uses this function to determine if the two trees are symmetric.
📋 What You'll Learn
Create two binary trees using nested objects with
val, left, and right propertiesCreate a helper function called
isMirror that takes two nodes and checks if they are mirror imagesCreate a function called
areSymmetric that uses isMirror to check if the two trees are symmetricPrint
true or false based on whether the trees are symmetric💡 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 tree data structures and algorithms.
Progress0 / 4 steps