Question: Write a method called combineWith that accepts another binary tree of integers as a parameter and combines the two trees into a new third tree

Write a method called combineWith that accepts another binary tree of integers as a parameter and combines the two trees into a new third tree that is returned. The new tree’s structure should be a union of the structures of the two original trees; it should have a node in any location where there was a node in either of the original trees (or both). The nodes of the new tree should store an integer indicating which of the original trees had a node at that position (1 if just the first tree had the node, 2 if just the second tree had the node, and 3 if both trees had the node). Your method should not change the structure or contents of either of the two original trees that are being combined. For example, suppose IntTree variables t2 and t3 refer to reference trees #2 and #3, respectively. The call of t2.combineWith(t3) will return a reference to the following new tree. Keep in mind that nodes numbered 1 are those that appear only in t2 , nodes numbered 2 appear only in t3 , and nodes numbered 3 appear in both.

3 1 Reference Tree #2 2. Reference Tree #1 7. 1 4 Reference Tree #3 7 1. 3. 3. 2. 3.

3 1 Reference Tree #2 2. Reference Tree #1 7. 1 4 Reference Tree #3 7 1. 3. 3. 2. 3.

Step by Step Solution

3.33 Rating (177 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

public IntTree combineWith IntTree other IntTree res... View full answer

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 Building Java Programs A Back to Basics Approach Questions!