Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data Fundamentals Concepts, Drivers & Techniques

Authors: Thomas Erl, Wajid Khattak, Paul Buhler

1st Edition

0134291204, 9780134291208

More Books

Students also viewed these Databases questions

Question

fscanf retums a special value EOF that stands for...

Answered: 1 week ago

Question

4. EMC Corporation

Answered: 1 week ago

Question

6. Vanguard

Answered: 1 week ago