Write a Java program to find given two trees are mirror Image or not ?

By | July 16, 2020

In this post, We will Write a Java program to find given two trees are mirror image or not?

This Problem is the extension of  Find a mirror image of a binary tree

A mirror image of a binary tree is another binary tree with left and right children of all non-leaf nodes of the given binary tree are interchanged.

Below are the images that show the given Binary Tree & mirror image of a given binary tree.

Mirror Image of Binary Tree

PreOrder Output of Given Binary Tree: 1 2 4 5 3 6 7                                            PreOrder Mirror Image of Binary Tree: 1 3 7 6 2 5 4

If we input the Above two trees to our Algorithm then it should pass the criteria(Both trees are a mirror image of each other) and must return true.

Below is the Complete Source code: 

BinaryTree.java

 

ClientTest.java

The output of This Program:

PreOrder Processing output of Both Trees are….
1 2 4 5 3 6 7
1 3 7 6 2 5 4
——————————-
Both Binary Trees are mirror image of each other

You May Also Like:

Introduction to Tree Data Structure
Introduction to Binary Tree
Difference between binary and binary search trees
Structure of Binary Trees
Operations and use of Binary Trees
Insert operation in a binary search tree
Delete operation in a binary search tree
Search operation in a binary search tree
Find the sum of all elements in Binary Tree
Find the height or depth of a binary tree
Binary Tree Traversals
PreOrder traversal of binary tree implementation in Java
InOrder traversal of binary tree implementation in Java
PostOrder traversal of binary tree implementation in Java
Find the node with minimum and maximum values in a Binary Search Tree
Find a mirror image of a binary tree
How do you find if two given binary trees are the same or identical

That’s all about Write a Java program to find given two trees are mirror image or not ?
If you have any feedback or suggestion please feel free to drop in below comment box.

Leave a Reply

Your email address will not be published.