SlideShare a Scribd company logo
1 of 3
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.
<p>
The comparison of two empty trees is the empty tree.
<p>
The comparison of an empty tree and a non-empty tree
is the empty tree.
<p>
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())
<p>
The comparison of two non-empty binary trees is defined
recursively using the above three cases.
<p>
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 <T> BTreeAbstract<Boolean> compareBTrees(BTree<T> btree1,
BTree<T> btree2)
{
}
// Simple test case for compareBTrees().
public static void main(String[] args)
{
BTree<Integer> btree1 =
new LinkedBTree<>(10,
new LinkedBTree<>(20,
new LinkedBTree<>(40),
new LinkedBTree<>()), // empty tree
new LinkedBTree<>(30,
new LinkedBTree<>(50),
new LinkedBTree<>(60)));
BTree<Integer> 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<Boolean> 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");
}
}
JAVA - Please complete the method compareBTrees() below-  -- -- import.docx

More Related Content

Similar to JAVA - Please complete the method compareBTrees() below- -- -- import.docx

Write a program in Java to implement the ADT Binary Tree part of who.docx
Write a program in Java to implement the ADT Binary Tree part of who.docxWrite a program in Java to implement the ADT Binary Tree part of who.docx
Write a program in Java to implement the ADT Binary Tree part of who.docx
rochellwa9f
 
Bayesian Co clustering
Bayesian Co clusteringBayesian Co clustering
Bayesian Co clustering
lau
 

Similar to JAVA - Please complete the method compareBTrees() below- -- -- import.docx (7)

Write a program in Java to implement the ADT Binary Tree part of who.docx
Write a program in Java to implement the ADT Binary Tree part of who.docxWrite a program in Java to implement the ADT Binary Tree part of who.docx
Write a program in Java to implement the ADT Binary Tree part of who.docx
 
Bayesian Co clustering
Bayesian Co clusteringBayesian Co clustering
Bayesian Co clustering
 
The aggregate function - from sequential and parallel folds to parallel aggre...
The aggregate function - from sequential and parallel folds to parallel aggre...The aggregate function - from sequential and parallel folds to parallel aggre...
The aggregate function - from sequential and parallel folds to parallel aggre...
 
Query Optimization - Brandon Latronica
Query Optimization - Brandon LatronicaQuery Optimization - Brandon Latronica
Query Optimization - Brandon Latronica
 
Trees in Data Structure
Trees in Data StructureTrees in Data Structure
Trees in Data Structure
 
Binary Trees
Binary TreesBinary Trees
Binary Trees
 
ch14
ch14ch14
ch14
 

More from lucilabevin

Jeffrey has a company with 100 employees- Over the past quarter he has.docx
Jeffrey has a company with 100 employees- Over the past quarter he has.docxJeffrey has a company with 100 employees- Over the past quarter he has.docx
Jeffrey has a company with 100 employees- Over the past quarter he has.docx
lucilabevin
 
Jane- who is married to Stuart- and Betty- a divorced single parent- h.docx
Jane- who is married to Stuart- and Betty- a divorced single parent- h.docxJane- who is married to Stuart- and Betty- a divorced single parent- h.docx
Jane- who is married to Stuart- and Betty- a divorced single parent- h.docx
lucilabevin
 
Introduction to Pest Biology Lab Manual- Try to complete this matching.docx
Introduction to Pest Biology Lab Manual- Try to complete this matching.docxIntroduction to Pest Biology Lab Manual- Try to complete this matching.docx
Introduction to Pest Biology Lab Manual- Try to complete this matching.docx
lucilabevin
 

More from lucilabevin (20)

JKCorp- was listed in the US- sock marke- and isued lever 2 ADR- Whot.docx
JKCorp- was listed in the US- sock marke- and isued lever 2 ADR- Whot.docxJKCorp- was listed in the US- sock marke- and isued lever 2 ADR- Whot.docx
JKCorp- was listed in the US- sock marke- and isued lever 2 ADR- Whot.docx
 
Jeffrey has a company with 100 employees- Over the past quarter he has.docx
Jeffrey has a company with 100 employees- Over the past quarter he has.docxJeffrey has a company with 100 employees- Over the past quarter he has.docx
Jeffrey has a company with 100 employees- Over the past quarter he has.docx
 
JCL Inc- is a major chip manufacturing firm that sells its products to (3).docx
JCL Inc- is a major chip manufacturing firm that sells its products to (3).docxJCL Inc- is a major chip manufacturing firm that sells its products to (3).docx
JCL Inc- is a major chip manufacturing firm that sells its products to (3).docx
 
Java-Data structure Write a method that reverses the order of elemen.docx
Java-Data structure   Write a method that reverses the order of elemen.docxJava-Data structure   Write a method that reverses the order of elemen.docx
Java-Data structure Write a method that reverses the order of elemen.docx
 
JAVA please How do we implement a circular array Create an array of si.docx
JAVA please How do we implement a circular array Create an array of si.docxJAVA please How do we implement a circular array Create an array of si.docx
JAVA please How do we implement a circular array Create an array of si.docx
 
java Implement an algorithm to find the nth to the last element of a s.docx
java Implement an algorithm to find the nth to the last element of a s.docxjava Implement an algorithm to find the nth to the last element of a s.docx
java Implement an algorithm to find the nth to the last element of a s.docx
 
Jarrod became the father of triplets on June 20- On what date is he.docx
Jarrod became the father of triplets on June 20-   On what date is he.docxJarrod became the father of triplets on June 20-   On what date is he.docx
Jarrod became the father of triplets on June 20- On what date is he.docx
 
Janelle is a sixth-grade student who experiences hearing loss- When Ja.docx
Janelle is a sixth-grade student who experiences hearing loss- When Ja.docxJanelle is a sixth-grade student who experiences hearing loss- When Ja.docx
Janelle is a sixth-grade student who experiences hearing loss- When Ja.docx
 
Jane- who is married to Stuart- and Betty- a divorced single parent- h.docx
Jane- who is married to Stuart- and Betty- a divorced single parent- h.docxJane- who is married to Stuart- and Betty- a divorced single parent- h.docx
Jane- who is married to Stuart- and Betty- a divorced single parent- h.docx
 
It is the responsibility of the stakeholders to identify themselves to.docx
It is the responsibility of the stakeholders to identify themselves to.docxIt is the responsibility of the stakeholders to identify themselves to.docx
It is the responsibility of the stakeholders to identify themselves to.docx
 
Isabei Briggs Myers was a pioneer in the study of personality types- T.docx
Isabei Briggs Myers was a pioneer in the study of personality types- T.docxIsabei Briggs Myers was a pioneer in the study of personality types- T.docx
Isabei Briggs Myers was a pioneer in the study of personality types- T.docx
 
Issue Materiality is to Sustainability Materiality as Stakeholder Mana.docx
Issue Materiality is to Sustainability Materiality as Stakeholder Mana.docxIssue Materiality is to Sustainability Materiality as Stakeholder Mana.docx
Issue Materiality is to Sustainability Materiality as Stakeholder Mana.docx
 
Inflammatory bowel disease (IBD) is an autoimmune disorder impacting t.docx
Inflammatory bowel disease (IBD) is an autoimmune disorder impacting t.docxInflammatory bowel disease (IBD) is an autoimmune disorder impacting t.docx
Inflammatory bowel disease (IBD) is an autoimmune disorder impacting t.docx
 
is often used for interaction structure prediction)- Questions for Dis.docx
is often used for interaction structure prediction)- Questions for Dis.docxis often used for interaction structure prediction)- Questions for Dis.docx
is often used for interaction structure prediction)- Questions for Dis.docx
 
Ip Task- Study- mor rests e car for en ogroed pobiod oi The bemaked on.docx
Ip Task- Study- mor rests e car for en ogroed pobiod oi The bemaked on.docxIp Task- Study- mor rests e car for en ogroed pobiod oi The bemaked on.docx
Ip Task- Study- mor rests e car for en ogroed pobiod oi The bemaked on.docx
 
Introduction- Take this quiz to get a quick check on your understandin.docx
Introduction- Take this quiz to get a quick check on your understandin.docxIntroduction- Take this quiz to get a quick check on your understandin.docx
Introduction- Take this quiz to get a quick check on your understandin.docx
 
Introduction to Minerals and Rocks A large segment of geology is the s.docx
Introduction to Minerals and Rocks A large segment of geology is the s.docxIntroduction to Minerals and Rocks A large segment of geology is the s.docx
Introduction to Minerals and Rocks A large segment of geology is the s.docx
 
Introduction to Pest Biology Lab Manual- Try to complete this matching.docx
Introduction to Pest Biology Lab Manual- Try to complete this matching.docxIntroduction to Pest Biology Lab Manual- Try to complete this matching.docx
Introduction to Pest Biology Lab Manual- Try to complete this matching.docx
 
In which organisms a part of the genetic code has alternative reading-.docx
In which organisms a part of the genetic code has alternative reading-.docxIn which organisms a part of the genetic code has alternative reading-.docx
In which organisms a part of the genetic code has alternative reading-.docx
 
intermediate accounting II CH 14 Question 1- Early extinguishment of d.docx
intermediate accounting II CH 14 Question 1- Early extinguishment of d.docxintermediate accounting II CH 14 Question 1- Early extinguishment of d.docx
intermediate accounting II CH 14 Question 1- Early extinguishment of d.docx
 

Recently uploaded

Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
MateoGardella
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
SanaAli374401
 

Recently uploaded (20)

Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 

JAVA - Please complete the method compareBTrees() below- -- -- import.docx

  • 1. 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. <p> The comparison of two empty trees is the empty tree. <p> The comparison of an empty tree and a non-empty tree is the empty tree. <p> 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()) <p> The comparison of two non-empty binary trees is defined recursively using the above three cases. <p> 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 <T> BTreeAbstract<Boolean> compareBTrees(BTree<T> btree1, BTree<T> btree2) { }
  • 2. // Simple test case for compareBTrees(). public static void main(String[] args) { BTree<Integer> btree1 = new LinkedBTree<>(10, new LinkedBTree<>(20, new LinkedBTree<>(40), new LinkedBTree<>()), // empty tree new LinkedBTree<>(30, new LinkedBTree<>(50), new LinkedBTree<>(60))); BTree<Integer> 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<Boolean> 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"); } }