Objective: Given Two binary Search Trees, Check if both are identical.
Input: Two binary Search Trees
Approach:
- 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.
Complete Code:
Output-
true false