top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

How to find if a binary tree is mirror image of another binary tree?

+4 votes
412 views

Code example will help.

posted Oct 21, 2013 by anonymous

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

2 Answers

+3 votes
boolean tree_compare (tree *roort1, tree *root2)
{
    if ((root1 == NULL) && (root2 == NULL))
    {
        return TRUE;
    }
    else if (root1 && root2)
    {
        if(root1->data == root2->data)
        {
            return (tree_compare(roort1->right, root2->left) && tree_compare(root1->left, roort2->right))
        }
        else
            return FALSE;
    }
    else
        FALSE;
}
answer Oct 21, 2013 by Vikas Upadhyay
–2 votes

A binary tree is a mirror image of itself if its left and right subtrees are identical mirror images i.e., the binary tree is symmetrical.

boolean isMirror(BTree tree) {
  foreach (List<Integer> row : tree.rows() {
    if (row != row.reverse()) return false;
  }
  return true;
}
answer Oct 21, 2013 by Atul Mishra
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...