Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA - Please complete the method compareBTrees() below: /* */ import binarytree.*; /** A program that tests the addStringBTrees() and addIntegerBTrees() methods. */ public class

JAVA - Please complete the method compareBTrees() below:

/*

*/

import binarytree.*;

/** A program that tests the addStringBTrees() and addIntegerBTrees() methods. */ public class CompareBTrees { /** Return a binary tree that is the node-by-node comparison of the two input trees.

The comparison of two empty trees is the empty tree.

The comparison of an empty tree and a non-empty tree is the empty tree.

The comparison of two non-empty trees, btree1 and btree2, is a tree whose root data element is a boolean holding the value btree1.root().equals(btree2.root())

The comparison of two non-empty binary trees is defined recursively using the above three cases.

Another way to describe the result tree is that a node of the result tree holds true if both input trees have that node and their contents are equal, and a node of the result tree holds false if both input trees have that node and their contents are not equal. So the result tree has nodes only at those positions where both input trees have a node. You might say that the result tree has the shape of the "intersection" of the two input trees (compare this with the AddBTrees.addStringBTrees() and AddBTrees.addIntegerBTrees() methods). */ public static BTreeAbstract compareBTrees(BTree btree1, BTree btree2) {

}

// Simple test case for compareBTrees(). public static void main(String[] args) { BTree btree1 = new LinkedBTree<>(10, new LinkedBTree<>(20, new LinkedBTree<>(40), new LinkedBTree<>()), // empty tree new LinkedBTree<>(30, new LinkedBTree<>(50), new LinkedBTree<>(60)));

BTree btree2 = new LinkedBTree<>(10, new LinkedBTree<>(30, new LinkedBTree<>(), // empty tree new LinkedBTree<>(40)), new LinkedBTree<>(20, new LinkedBTree<>(50), new LinkedBTree<>())); // empty tree

BTree btree3 = compareBTrees(btree1, btree2);

System.out.println( btree1 ); System.out.println( btree2 ); System.out.println( btree3 ); BTree2dot.btree2dot(btree1, "btree1"); BTree2png.btree2png("btree1"); BTree2dot.btree2dot(btree2, "btree2"); BTree2png.btree2png("btree2"); BTree2dot.btree2dot(btree3, "btree3"); BTree2png.btree2png("btree3"); } }

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

Spatial Database Systems Design Implementation And Project Management

Authors: Albert K.W. Yeung, G. Brent Hall

1st Edition

1402053932, 978-1402053931

More Books

Students also viewed these Databases questions