Given a binary tree, check whether it is a mirror of itself.
For example, this binary tree is symmetric:
1 / \ 2 2 / \ / \ 3 4 4 3
But the following is not:
1 / \ 2 2 \ \ 3 3
The idea is to write a recursive function isMirror() that takes two trees as an argument and returns true if trees are the mirror and false if trees are not mirror. The isMirror() function recursively checks two roots and subtrees under the root.
Below is the implementation of the above algorithm.
This article is contributed by Muneer Ahmed. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Sum of the mirror image nodes of a complete binary tree in an inorder way
- Number of edges in mirror image of Complete binary tree
- Convert a Binary Tree into its Mirror Tree
- Construct Full Binary Tree using its Preorder traversal and Preorder traversal of its mirror tree
- Create a mirror tree from the given binary tree
- Check for Symmetric Binary Tree (Iterative Approach)
- Symmetric Binary Tree
- Node having maximum sum of immediate children and itself in n-ary tree
- Check whether every node of binary tree has a value K on itself or its any immediate neighbours
- Count nodes having highest value in the path from root to itself in a Binary Tree
- Count nodes having smallest value in the path from root to itself in a Binary Tree
- Mirror of n-ary Tree
- Find mirror of a given node in Binary tree
- Check mirror in n-ary tree
- Smallest window that contains all characters of string itself
- Check if two trees are Mirror
- Iterative method to check if two trees are mirror of each other
- Check if two trees are Mirror | Set 2
- Check if two trees are mirror of each other using level order traversal
- Complexity of different operations in Binary tree, Binary Search Tree and AVL tree