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
Get step-by-step solutions from verified subject matter experts
