Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Pinterest
Share On Reddit
Share On Stumbleupon
Contact us
Hide Buttons

Check If One Binary is Mirror Tree of another Binary Tree.

Objec­tive: - Given two binary trees check if they are mir­ror image of each other.

Exam­ple:

Check-If-One-Binary-is-Mirror-Tree-of-another-Binary-Tree

Check-If-One-Binary-is-Mirror-Tree-of-another-Binary-Tree

Approach:

  • Do the pre­order tra­ver­sal on both the trees simultaneously.
  • if any node doesn’t have cor­re­spond­ing node in the another tree, return false.
  • check if left node in one tree is the right node in another tree, and vice verse.

Code:


Out­put:

Is Mirror Trees : true

You may also like...

  • san­jib

    add data check for com­plete­ness of the pro­gram
    if(root1.data !=root2.data){

    return false;

    }

    • tuto­ri­al­hori­zon

      Thanks san­jib, updated it 🙂