Question: What this program is trying to do is compare two binary trees and see if they have different elements but the binary trees can have

What this program is trying to do is compare two binary trees and see if they have different elements but the binary trees can have different structures, I'm stuck trying to figure out how to exit out of the recursive statement and have the program actually function and pass all the test. Here is the code I have:

private static boolean problem1Recursive(Node t1, Node t2)

{

if(t1 == null)

{

return false;

}

else if(find(t2, t1.key))

{

return find(t2, t1.key);

}

return (problem1Recursive(t1.left, t2) && problem1Recursive(t1.right, t2));

}

and here is the code for that find function:

private static boolean find(Node root, int key){

if(root == null)

{

return false;

}

if(root.key == key)

{

return true;

}

if(key < root.key)

{

return find(root.left, key);

}

else

{

return find(root.right, key);

}

}

I'd deeply apprecaite help on this so I can better understand binary trees.

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!