SlideShare a Scribd company logo
1 of 2
Download to read offline
On the code which has a class in which I implementing a binary tree using an array. This array,
named store, stores Node in entries corresponding to
nodes in the tree and null if the node does not exist. Complete the countLeavesmethod so that it
returns the number of leaves in this tree.
Code:
Solution
import java.util.AbstractSet; import java.util.Arrays; import java.util.Iterator; import
java.util.NoSuchElementException; /** * Implementation of an abstract set using an array-
based binary tree. This is * used to help teach binary tree's and will have more details explained
in * future lectures. * * @author William J. Collins * @author Matthew Hertz * @param
Data type (which must be Comparable) of the elements in this tree. */ public class
ArrayBinaryTree> extends AbstractSet { /** Entry in the data store where the root node can be
found. */ private static final int ROOT = 0; /** Array used to store the nodes which consist of
this binary tree. */ protected Node[] store; /** Number of elements within the tree. */
protected int size; /** * Initializes this ArrayBinaryTree object to be empty. This creates the
array * in which items will be stored. */ @SuppressWarnings("unchecked") public
ArrayBinaryTree() { store = new Node[63]; size = 0; } /** * Initializes this
ArrayBinaryTree object to contain a shallow copy of a * specified ArrayBinaryTree object.
The worstTime(n) is O(n), where n is the * number of elements in the specified
ArrayBinaryTree object. * * @param otherTree The tree which will be copied to create our
new tree, */ @SuppressWarnings("unchecked") public ArrayBinaryTree(ArrayBinaryTree
otherTree) { store = (Node[]) Arrays.copyOf(otherTree.store, otherTree.store.length); size =
otherTree.size; } public int countLeaves() { } /** * Returns the size of this
ArrayBinaryTree object. * * @return the size of this ArrayBinaryTree object. */
@Override public int size() { return size; } /** * Returns an iterator that will return the
elements in this ArrayBinaryTree, * but without any specific ordering. * * @return Iterator
positioned at the smallest element in this ArrayBinaryTree * object. */ @Override
public Iterator iterator() { return new ArrayTreeIterator(); } /** * Determines if there is at
least one element in this ArrayBinaryTree object * that equals a specified element. The
worstTime(n) is O(n) and * averageTime(n) is O(log n). * * @param obj - the element
sought in this ArrayBinaryTree object. * @return true - if there is an element in this
ArrayBinaryTree object that * equals obj; otherwise, return false. * @throws
ClassCastException - if obj cannot be compared to the elements in * this
ArrayBinaryTree object. * @throws NullPointerException - if obj is null. */ @Override
public boolean contains(Object obj) { return getEntry(obj) != null; } /** * Ensures that
this ArrayBinaryTree object contains a specified element. The * worstTime(n) is O(n) for this
addition. * * @param element Element we want to be certain is contained within this *
ArrayBinaryTree * @return True if the element had not been in ArrayBinaryTree and so was
just * added; false if the element was already in the ArrayBinaryTree and * so did
not need to be added or was null and so cannot be added. */ @Override public boolean
add(E element) { // Null objects cannot be added to this Collection if (element == null) {
return false; } // Handle the easy case when the tree has no elements if (isEmpty()) {
Node root = new Node(element, ROOT); store[ROOT] = root; size++ ; return true;
} // Handle the most common case -- adding the element to the end of the tree. else { int
idx = ROOT; // Find the location where this element should be added in the tree while
(true) { int comp = element.compareTo(store[idx].element); // The Set ADT definition
only allows the Collection to contain a single // copy of an element; if this element had been
previously added, we // should just return false if (comp == 0) { return false;
} // If it is smaller, we should traverse to the left child else if (comp < 0) { idx =
(idx * 2) + 1; } // Otherwise it must be larger, so we should traverse to the right child
else { idx = (idx * 2) + 2; } // When the array is not large enough to hold the
new element at the // location at which it needs to be added

More Related Content

Similar to On the code which has a class in which I implementing a binary tree .pdf

5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf
5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf
5. Design and implement a method contains 2 for BinarySearchTree, fu.pdframbagra74
 
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docx
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docxweek4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docx
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docxalanfhall8953
 
Please write in C++ and should be able to compile and debug.Thank yo.pdf
Please write in C++ and should be able to compile and debug.Thank yo.pdfPlease write in C++ and should be able to compile and debug.Thank yo.pdf
Please write in C++ and should be able to compile and debug.Thank yo.pdfajaycosmeticslg
 
Please complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docxPlease complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docxcgraciela1
 
Everything needs to be according to the instructions- thank you! SUPPO.pdf
Everything needs to be according to the instructions- thank you! SUPPO.pdfEverything needs to be according to the instructions- thank you! SUPPO.pdf
Everything needs to be according to the instructions- thank you! SUPPO.pdffirstchoiceajmer
 
Given the following class in Java- public class ThreeTenDynArray-T- {.pdf
Given the following class in Java-  public class ThreeTenDynArray-T- {.pdfGiven the following class in Java-  public class ThreeTenDynArray-T- {.pdf
Given the following class in Java- public class ThreeTenDynArray-T- {.pdfNicholasflqStewartl
 
For this lab you will complete the class MyArrayList by implementing.pdf
For this lab you will complete the class MyArrayList by implementing.pdfFor this lab you will complete the class MyArrayList by implementing.pdf
For this lab you will complete the class MyArrayList by implementing.pdffashiongallery1
 
Note- Can someone help me with the Public boolean add(E value) method.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdfNote- Can someone help me with the Public boolean add(E value) method.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdfStewart29UReesa
 
Given the code below create a method called, getCollisionCount that .pdf
Given the code below create a method called, getCollisionCount that .pdfGiven the code below create a method called, getCollisionCount that .pdf
Given the code below create a method called, getCollisionCount that .pdfaucmistry
 
package com.java2novice.ds.linkedlist;import java.util.NoSuchEleme.pdf
package com.java2novice.ds.linkedlist;import java.util.NoSuchEleme.pdfpackage com.java2novice.ds.linkedlist;import java.util.NoSuchEleme.pdf
package com.java2novice.ds.linkedlist;import java.util.NoSuchEleme.pdfaptind
 
Write a program that will test a name) method no sorting routine from.docx
 Write a program that will test a name) method no sorting routine from.docx Write a program that will test a name) method no sorting routine from.docx
Write a program that will test a name) method no sorting routine from.docxajoy21
 
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfGetting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfinfo309708
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfravikapoorindia
 
Complete code in Java The hashtable you'll be making will use String.pdf
Complete code in Java   The hashtable you'll be making will use String.pdfComplete code in Java   The hashtable you'll be making will use String.pdf
Complete code in Java The hashtable you'll be making will use String.pdfaarifi9988
 
java I am trying to run my code but it is not letting me .pdf
java    I am trying to run my code but it is not letting me .pdfjava    I am trying to run my code but it is not letting me .pdf
java I am trying to run my code but it is not letting me .pdfadinathassociates
 
Modifications highlighted in bold lettersDropOutStack.javaim.pdf
Modifications highlighted in bold lettersDropOutStack.javaim.pdfModifications highlighted in bold lettersDropOutStack.javaim.pdf
Modifications highlighted in bold lettersDropOutStack.javaim.pdfLalkamal2
 
The hashtable youll be making will use Strings as the keys and Obje.pdf
The hashtable youll be making will use Strings as the keys and Obje.pdfThe hashtable youll be making will use Strings as the keys and Obje.pdf
The hashtable youll be making will use Strings as the keys and Obje.pdfvicky309441
 
Assg 12 Binary Search Trees COSC 2336assg-12.cppAssg 12 Binary .docx
Assg 12 Binary Search Trees COSC 2336assg-12.cppAssg 12 Binary .docxAssg 12 Binary Search Trees COSC 2336assg-12.cppAssg 12 Binary .docx
Assg 12 Binary Search Trees COSC 2336assg-12.cppAssg 12 Binary .docxfestockton
 
Assignment 9 (Parent reference for BST) Redefine TreeNode by adding .pdf
Assignment 9 (Parent reference for BST) Redefine TreeNode by adding .pdfAssignment 9 (Parent reference for BST) Redefine TreeNode by adding .pdf
Assignment 9 (Parent reference for BST) Redefine TreeNode by adding .pdfFootageetoffe16
 

Similar to On the code which has a class in which I implementing a binary tree .pdf (20)

5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf
5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf
5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf
 
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docx
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docxweek4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docx
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docx
 
Please write in C++ and should be able to compile and debug.Thank yo.pdf
Please write in C++ and should be able to compile and debug.Thank yo.pdfPlease write in C++ and should be able to compile and debug.Thank yo.pdf
Please write in C++ and should be able to compile and debug.Thank yo.pdf
 
Please complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docxPlease complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docx
 
Everything needs to be according to the instructions- thank you! SUPPO.pdf
Everything needs to be according to the instructions- thank you! SUPPO.pdfEverything needs to be according to the instructions- thank you! SUPPO.pdf
Everything needs to be according to the instructions- thank you! SUPPO.pdf
 
Given the following class in Java- public class ThreeTenDynArray-T- {.pdf
Given the following class in Java-  public class ThreeTenDynArray-T- {.pdfGiven the following class in Java-  public class ThreeTenDynArray-T- {.pdf
Given the following class in Java- public class ThreeTenDynArray-T- {.pdf
 
For this lab you will complete the class MyArrayList by implementing.pdf
For this lab you will complete the class MyArrayList by implementing.pdfFor this lab you will complete the class MyArrayList by implementing.pdf
For this lab you will complete the class MyArrayList by implementing.pdf
 
Note- Can someone help me with the Public boolean add(E value) method.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdfNote- Can someone help me with the Public boolean add(E value) method.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdf
 
Given the code below create a method called, getCollisionCount that .pdf
Given the code below create a method called, getCollisionCount that .pdfGiven the code below create a method called, getCollisionCount that .pdf
Given the code below create a method called, getCollisionCount that .pdf
 
package com.java2novice.ds.linkedlist;import java.util.NoSuchEleme.pdf
package com.java2novice.ds.linkedlist;import java.util.NoSuchEleme.pdfpackage com.java2novice.ds.linkedlist;import java.util.NoSuchEleme.pdf
package com.java2novice.ds.linkedlist;import java.util.NoSuchEleme.pdf
 
Advanced core java
Advanced core javaAdvanced core java
Advanced core java
 
Write a program that will test a name) method no sorting routine from.docx
 Write a program that will test a name) method no sorting routine from.docx Write a program that will test a name) method no sorting routine from.docx
Write a program that will test a name) method no sorting routine from.docx
 
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfGetting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdf
 
Complete code in Java The hashtable you'll be making will use String.pdf
Complete code in Java   The hashtable you'll be making will use String.pdfComplete code in Java   The hashtable you'll be making will use String.pdf
Complete code in Java The hashtable you'll be making will use String.pdf
 
java I am trying to run my code but it is not letting me .pdf
java    I am trying to run my code but it is not letting me .pdfjava    I am trying to run my code but it is not letting me .pdf
java I am trying to run my code but it is not letting me .pdf
 
Modifications highlighted in bold lettersDropOutStack.javaim.pdf
Modifications highlighted in bold lettersDropOutStack.javaim.pdfModifications highlighted in bold lettersDropOutStack.javaim.pdf
Modifications highlighted in bold lettersDropOutStack.javaim.pdf
 
The hashtable youll be making will use Strings as the keys and Obje.pdf
The hashtable youll be making will use Strings as the keys and Obje.pdfThe hashtable youll be making will use Strings as the keys and Obje.pdf
The hashtable youll be making will use Strings as the keys and Obje.pdf
 
Assg 12 Binary Search Trees COSC 2336assg-12.cppAssg 12 Binary .docx
Assg 12 Binary Search Trees COSC 2336assg-12.cppAssg 12 Binary .docxAssg 12 Binary Search Trees COSC 2336assg-12.cppAssg 12 Binary .docx
Assg 12 Binary Search Trees COSC 2336assg-12.cppAssg 12 Binary .docx
 
Assignment 9 (Parent reference for BST) Redefine TreeNode by adding .pdf
Assignment 9 (Parent reference for BST) Redefine TreeNode by adding .pdfAssignment 9 (Parent reference for BST) Redefine TreeNode by adding .pdf
Assignment 9 (Parent reference for BST) Redefine TreeNode by adding .pdf
 

More from wasemanivytreenrco51

Explain what differential cell affinity is, how this process is acco.pdf
Explain what differential cell affinity is, how this process is acco.pdfExplain what differential cell affinity is, how this process is acco.pdf
Explain what differential cell affinity is, how this process is acco.pdfwasemanivytreenrco51
 
Explain in detail how OFDM helps mitigates multipath fading effects..pdf
Explain in detail how OFDM helps mitigates multipath fading effects..pdfExplain in detail how OFDM helps mitigates multipath fading effects..pdf
Explain in detail how OFDM helps mitigates multipath fading effects..pdfwasemanivytreenrco51
 
Entamoeba histolytica is an amoeba responsible for the gastrointestin.pdf
Entamoeba histolytica is an amoeba responsible for the gastrointestin.pdfEntamoeba histolytica is an amoeba responsible for the gastrointestin.pdf
Entamoeba histolytica is an amoeba responsible for the gastrointestin.pdfwasemanivytreenrco51
 
Describe briefly each mouth part of the grasshopper. b. Describe how.pdf
Describe briefly each mouth part of the grasshopper.  b. Describe how.pdfDescribe briefly each mouth part of the grasshopper.  b. Describe how.pdf
Describe briefly each mouth part of the grasshopper. b. Describe how.pdfwasemanivytreenrco51
 
Contrast the views of Piaget and Bandura on how children develop..pdf
Contrast the views of Piaget and Bandura on how children develop..pdfContrast the views of Piaget and Bandura on how children develop..pdf
Contrast the views of Piaget and Bandura on how children develop..pdfwasemanivytreenrco51
 
Compute the probability of event E if the odds in favor of E are 31.pdf
Compute the probability of event E if the odds in favor of E are  31.pdfCompute the probability of event E if the odds in favor of E are  31.pdf
Compute the probability of event E if the odds in favor of E are 31.pdfwasemanivytreenrco51
 
Compare and contrast the world population with that of the United St.pdf
Compare and contrast the world population with that of the United St.pdfCompare and contrast the world population with that of the United St.pdf
Compare and contrast the world population with that of the United St.pdfwasemanivytreenrco51
 
8. What protocol is are layers 6 and 7 of the OSI model based on.pdf
8. What protocol is are layers 6 and 7 of the OSI model based on.pdf8. What protocol is are layers 6 and 7 of the OSI model based on.pdf
8. What protocol is are layers 6 and 7 of the OSI model based on.pdfwasemanivytreenrco51
 
Which statement is true of serous membranesA) They line closed cavi.pdf
Which statement is true of serous membranesA) They line closed cavi.pdfWhich statement is true of serous membranesA) They line closed cavi.pdf
Which statement is true of serous membranesA) They line closed cavi.pdfwasemanivytreenrco51
 
Which of the following is not included in the calculation of the VIX .pdf
Which of the following is not included in the calculation of the VIX .pdfWhich of the following is not included in the calculation of the VIX .pdf
Which of the following is not included in the calculation of the VIX .pdfwasemanivytreenrco51
 
What is an Accountable Care Organizations (ACO) How does an ACOs .pdf
What is an Accountable Care Organizations (ACO) How does an ACOs .pdfWhat is an Accountable Care Organizations (ACO) How does an ACOs .pdf
What is an Accountable Care Organizations (ACO) How does an ACOs .pdfwasemanivytreenrco51
 
True or false A selective force (such as antibiotics) must be prese.pdf
True or false A selective force (such as antibiotics) must be prese.pdfTrue or false A selective force (such as antibiotics) must be prese.pdf
True or false A selective force (such as antibiotics) must be prese.pdfwasemanivytreenrco51
 
The receptors in the feedback loop regulating ADH secretion are osmor.pdf
The receptors in the feedback loop regulating ADH secretion are osmor.pdfThe receptors in the feedback loop regulating ADH secretion are osmor.pdf
The receptors in the feedback loop regulating ADH secretion are osmor.pdfwasemanivytreenrco51
 
The UV spectrum of the hot B0V star is significantly below the conti.pdf
The UV spectrum of the hot B0V star is significantly below the conti.pdfThe UV spectrum of the hot B0V star is significantly below the conti.pdf
The UV spectrum of the hot B0V star is significantly below the conti.pdfwasemanivytreenrco51
 
Q2 For any drosophila population, what is the proportion of live ho.pdf
Q2 For any drosophila population, what is the proportion of live ho.pdfQ2 For any drosophila population, what is the proportion of live ho.pdf
Q2 For any drosophila population, what is the proportion of live ho.pdfwasemanivytreenrco51
 
Prove asymptotic upper and lower hounds for each of the following sp.pdf
Prove asymptotic upper and lower hounds for each of the following  sp.pdfProve asymptotic upper and lower hounds for each of the following  sp.pdf
Prove asymptotic upper and lower hounds for each of the following sp.pdfwasemanivytreenrco51
 
pls show details.thx 1. Consider the vectors v1 (a Find the projecti.pdf
pls show details.thx 1. Consider the vectors v1 (a Find the projecti.pdfpls show details.thx 1. Consider the vectors v1 (a Find the projecti.pdf
pls show details.thx 1. Consider the vectors v1 (a Find the projecti.pdfwasemanivytreenrco51
 
Please create an infographic for medical fraud! Thank you so much.pdf
Please create an infographic for medical fraud! Thank you so much.pdfPlease create an infographic for medical fraud! Thank you so much.pdf
Please create an infographic for medical fraud! Thank you so much.pdfwasemanivytreenrco51
 
Internet Programming. For event-driven architecture, how does pollin.pdf
Internet Programming. For event-driven architecture, how does pollin.pdfInternet Programming. For event-driven architecture, how does pollin.pdf
Internet Programming. For event-driven architecture, how does pollin.pdfwasemanivytreenrco51
 
PCAOB Please respond to the followingGo to the PCAOB Website..pdf
PCAOB Please respond to the followingGo to the PCAOB Website..pdfPCAOB Please respond to the followingGo to the PCAOB Website..pdf
PCAOB Please respond to the followingGo to the PCAOB Website..pdfwasemanivytreenrco51
 

More from wasemanivytreenrco51 (20)

Explain what differential cell affinity is, how this process is acco.pdf
Explain what differential cell affinity is, how this process is acco.pdfExplain what differential cell affinity is, how this process is acco.pdf
Explain what differential cell affinity is, how this process is acco.pdf
 
Explain in detail how OFDM helps mitigates multipath fading effects..pdf
Explain in detail how OFDM helps mitigates multipath fading effects..pdfExplain in detail how OFDM helps mitigates multipath fading effects..pdf
Explain in detail how OFDM helps mitigates multipath fading effects..pdf
 
Entamoeba histolytica is an amoeba responsible for the gastrointestin.pdf
Entamoeba histolytica is an amoeba responsible for the gastrointestin.pdfEntamoeba histolytica is an amoeba responsible for the gastrointestin.pdf
Entamoeba histolytica is an amoeba responsible for the gastrointestin.pdf
 
Describe briefly each mouth part of the grasshopper. b. Describe how.pdf
Describe briefly each mouth part of the grasshopper.  b. Describe how.pdfDescribe briefly each mouth part of the grasshopper.  b. Describe how.pdf
Describe briefly each mouth part of the grasshopper. b. Describe how.pdf
 
Contrast the views of Piaget and Bandura on how children develop..pdf
Contrast the views of Piaget and Bandura on how children develop..pdfContrast the views of Piaget and Bandura on how children develop..pdf
Contrast the views of Piaget and Bandura on how children develop..pdf
 
Compute the probability of event E if the odds in favor of E are 31.pdf
Compute the probability of event E if the odds in favor of E are  31.pdfCompute the probability of event E if the odds in favor of E are  31.pdf
Compute the probability of event E if the odds in favor of E are 31.pdf
 
Compare and contrast the world population with that of the United St.pdf
Compare and contrast the world population with that of the United St.pdfCompare and contrast the world population with that of the United St.pdf
Compare and contrast the world population with that of the United St.pdf
 
8. What protocol is are layers 6 and 7 of the OSI model based on.pdf
8. What protocol is are layers 6 and 7 of the OSI model based on.pdf8. What protocol is are layers 6 and 7 of the OSI model based on.pdf
8. What protocol is are layers 6 and 7 of the OSI model based on.pdf
 
Which statement is true of serous membranesA) They line closed cavi.pdf
Which statement is true of serous membranesA) They line closed cavi.pdfWhich statement is true of serous membranesA) They line closed cavi.pdf
Which statement is true of serous membranesA) They line closed cavi.pdf
 
Which of the following is not included in the calculation of the VIX .pdf
Which of the following is not included in the calculation of the VIX .pdfWhich of the following is not included in the calculation of the VIX .pdf
Which of the following is not included in the calculation of the VIX .pdf
 
What is an Accountable Care Organizations (ACO) How does an ACOs .pdf
What is an Accountable Care Organizations (ACO) How does an ACOs .pdfWhat is an Accountable Care Organizations (ACO) How does an ACOs .pdf
What is an Accountable Care Organizations (ACO) How does an ACOs .pdf
 
True or false A selective force (such as antibiotics) must be prese.pdf
True or false A selective force (such as antibiotics) must be prese.pdfTrue or false A selective force (such as antibiotics) must be prese.pdf
True or false A selective force (such as antibiotics) must be prese.pdf
 
The receptors in the feedback loop regulating ADH secretion are osmor.pdf
The receptors in the feedback loop regulating ADH secretion are osmor.pdfThe receptors in the feedback loop regulating ADH secretion are osmor.pdf
The receptors in the feedback loop regulating ADH secretion are osmor.pdf
 
The UV spectrum of the hot B0V star is significantly below the conti.pdf
The UV spectrum of the hot B0V star is significantly below the conti.pdfThe UV spectrum of the hot B0V star is significantly below the conti.pdf
The UV spectrum of the hot B0V star is significantly below the conti.pdf
 
Q2 For any drosophila population, what is the proportion of live ho.pdf
Q2 For any drosophila population, what is the proportion of live ho.pdfQ2 For any drosophila population, what is the proportion of live ho.pdf
Q2 For any drosophila population, what is the proportion of live ho.pdf
 
Prove asymptotic upper and lower hounds for each of the following sp.pdf
Prove asymptotic upper and lower hounds for each of the following  sp.pdfProve asymptotic upper and lower hounds for each of the following  sp.pdf
Prove asymptotic upper and lower hounds for each of the following sp.pdf
 
pls show details.thx 1. Consider the vectors v1 (a Find the projecti.pdf
pls show details.thx 1. Consider the vectors v1 (a Find the projecti.pdfpls show details.thx 1. Consider the vectors v1 (a Find the projecti.pdf
pls show details.thx 1. Consider the vectors v1 (a Find the projecti.pdf
 
Please create an infographic for medical fraud! Thank you so much.pdf
Please create an infographic for medical fraud! Thank you so much.pdfPlease create an infographic for medical fraud! Thank you so much.pdf
Please create an infographic for medical fraud! Thank you so much.pdf
 
Internet Programming. For event-driven architecture, how does pollin.pdf
Internet Programming. For event-driven architecture, how does pollin.pdfInternet Programming. For event-driven architecture, how does pollin.pdf
Internet Programming. For event-driven architecture, how does pollin.pdf
 
PCAOB Please respond to the followingGo to the PCAOB Website..pdf
PCAOB Please respond to the followingGo to the PCAOB Website..pdfPCAOB Please respond to the followingGo to the PCAOB Website..pdf
PCAOB Please respond to the followingGo to the PCAOB Website..pdf
 

Recently uploaded

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
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 ModeThiyagu K
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 

Recently uploaded (20)

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
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
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 

On the code which has a class in which I implementing a binary tree .pdf

  • 1. On the code which has a class in which I implementing a binary tree using an array. This array, named store, stores Node in entries corresponding to nodes in the tree and null if the node does not exist. Complete the countLeavesmethod so that it returns the number of leaves in this tree. Code: Solution import java.util.AbstractSet; import java.util.Arrays; import java.util.Iterator; import java.util.NoSuchElementException; /** * Implementation of an abstract set using an array- based binary tree. This is * used to help teach binary tree's and will have more details explained in * future lectures. * * @author William J. Collins * @author Matthew Hertz * @param Data type (which must be Comparable) of the elements in this tree. */ public class ArrayBinaryTree> extends AbstractSet { /** Entry in the data store where the root node can be found. */ private static final int ROOT = 0; /** Array used to store the nodes which consist of this binary tree. */ protected Node[] store; /** Number of elements within the tree. */ protected int size; /** * Initializes this ArrayBinaryTree object to be empty. This creates the array * in which items will be stored. */ @SuppressWarnings("unchecked") public ArrayBinaryTree() { store = new Node[63]; size = 0; } /** * Initializes this ArrayBinaryTree object to contain a shallow copy of a * specified ArrayBinaryTree object. The worstTime(n) is O(n), where n is the * number of elements in the specified ArrayBinaryTree object. * * @param otherTree The tree which will be copied to create our new tree, */ @SuppressWarnings("unchecked") public ArrayBinaryTree(ArrayBinaryTree otherTree) { store = (Node[]) Arrays.copyOf(otherTree.store, otherTree.store.length); size = otherTree.size; } public int countLeaves() { } /** * Returns the size of this ArrayBinaryTree object. * * @return the size of this ArrayBinaryTree object. */ @Override public int size() { return size; } /** * Returns an iterator that will return the elements in this ArrayBinaryTree, * but without any specific ordering. * * @return Iterator positioned at the smallest element in this ArrayBinaryTree * object. */ @Override public Iterator iterator() { return new ArrayTreeIterator(); } /** * Determines if there is at least one element in this ArrayBinaryTree object * that equals a specified element. The worstTime(n) is O(n) and * averageTime(n) is O(log n). * * @param obj - the element sought in this ArrayBinaryTree object. * @return true - if there is an element in this ArrayBinaryTree object that * equals obj; otherwise, return false. * @throws ClassCastException - if obj cannot be compared to the elements in * this ArrayBinaryTree object. * @throws NullPointerException - if obj is null. */ @Override
  • 2. public boolean contains(Object obj) { return getEntry(obj) != null; } /** * Ensures that this ArrayBinaryTree object contains a specified element. The * worstTime(n) is O(n) for this addition. * * @param element Element we want to be certain is contained within this * ArrayBinaryTree * @return True if the element had not been in ArrayBinaryTree and so was just * added; false if the element was already in the ArrayBinaryTree and * so did not need to be added or was null and so cannot be added. */ @Override public boolean add(E element) { // Null objects cannot be added to this Collection if (element == null) { return false; } // Handle the easy case when the tree has no elements if (isEmpty()) { Node root = new Node(element, ROOT); store[ROOT] = root; size++ ; return true; } // Handle the most common case -- adding the element to the end of the tree. else { int idx = ROOT; // Find the location where this element should be added in the tree while (true) { int comp = element.compareTo(store[idx].element); // The Set ADT definition only allows the Collection to contain a single // copy of an element; if this element had been previously added, we // should just return false if (comp == 0) { return false; } // If it is smaller, we should traverse to the left child else if (comp < 0) { idx = (idx * 2) + 1; } // Otherwise it must be larger, so we should traverse to the right child else { idx = (idx * 2) + 2; } // When the array is not large enough to hold the new element at the // location at which it needs to be added