Check if Two BST’s are Identical
Objective: Given Two binary Search Trees, Check if both are identical.
Input: Two binary Search Trees
- Travesre both trees at the same time, starting from root.
- Check if roots are not null and data are matched, if not, return false.
- Make recursice calls to root.left and root.right.
- If any of the tree gets over and other is not , return false.
- if both traversal of both trees ends at the same time, return true
- see code.
Top Companies Interview Questions..-
If you find anything incorrect or you feel that there is any better approach to solve the above problem, please write comment.