Check if Two BST’s are Identical

Objective: Given Two binary Search Trees, Check if both are identical.

Input: Two binary Search Trees

Check if Two BST's are Identical

Check if Two BST’s are Identical

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

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: