Check if two binary trees are Mirror of each other

In this post, we will see if two binary trees are mirror of each other.


Algorithm

Here is simple algorithm to check if two binary trees are mirror of each other

  • If root1 and root2 both are null, return true
  • If either of root1 and root2 is null, return false
  • Check “and condition” for below three conditions
    • Check if root1.data is equal to root2.data
    • Traverse with root1.left and root2.right
    • Traverse with root1.right and root2.left

Complete java program to count leaf nodes in binary tree

Output of above program

If two binary tree are mirror of each other: true
If two binary tree are mirror of each other: false

That’s all about how to check if two binary trees are Mirror of each other

Leave a Reply

Your email address will not be published. Required fields are marked *