Write C Code to Determine if Two Trees are Identical Two trees are identical when they have same data and arrangement of data is also same. To identify if two trees are identical, we need to traverse both trees simultaneously, and while traversing we need to compare data and children of the trees. Algorithm: sameTree(tree1, tree2) 1. If both trees are empty then return 1. 2. Else If both trees are non -empty (a) Check data of the root nodes (tree1->data == tree2->data) (b) Check left subtrees recursively i.e., call sameTree( tree1->left_subtree,
Read full article from Write C Code to Determine if Two Trees are Identical | GeeksforGeeks
No comments:
Post a Comment