Question: Write a method boolean sameTree(Node root1, Node root2) that takes the roots of two binary search trees as parameters and returns true if the trees

Write a method

boolean sameTree(Node root1, Node root2)

that takes the roots of two binary search trees as parameters and returns true if the trees are the same. Two trees are the same if they have exactly the same structure and values. Base case: If both trees are empty, return true. If one is empty and one is not empty, return false. Recursive case: Two trees are the same if their roots have the same data, and their left subtrees are the same, and their right subtrees are the same.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!