Home » Data Structure & Algorithms » Identical Binary Trees

Identical Binary Trees

Question :
WAP to find out if two binary tress are identical or not in O(n) time complexity.

Solution :
The problem is solved in recursive way.

Algorithm :
Step 1 : If both the trees are empty ,then return true.
Step 2 : Recursively traverse and check equality of left sub-tree,right sub-tree and data of each node of both trees.Return the result.
Step 3 : If one tree is empty and other is non-empty return false.

Program :


Leave a comment

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

thirteen − 1 =