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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started