QuestionQuestion

Binary Search Trees
ASSIGNMENT:         
Download the code from Canvas. First, explore the code to answer the questions. Then write code to answer some additional questions. Finally, add code to create an AVL tree.
1. In the downloaded code, six different classes and interfaces include the word “tree.” List them.
2. Which two from question #1 are interfaces?
3. Of the two interfaces from question #2, which one is the parent?
4. Of the four classes in question #1, which one…
a. represents a node in a tree?
b. represents a tree that doesn’t necessarily keep elements ordered?
c. represents a tree that keeps its elements ordered?
d. represents a list that is implemented with a tree?
e. For your answer to part (d) – does it implement an OrderedList or an UnorderedList?
5. LinkedBinarySearchTree has a parent class and it implements an interface.
a. What is its parent class?
b. What interface does it implement?
c. What would be the name of another class that could implement the interface? (If necessary, see 19.2 to remind yourself of other ways to implement trees. You do not need to actually implement another tree. This is just a reminder that there are other ways to implement trees besides links.)
6. Where is LinkedBinarySearchTree’s toString method? Hint: it is inherited.
a. Class:
b. Line number:
7. The addElement methods are overloaded in LinkedBinarySearchTree. What are the parameters for the two versions?
a. Parameter for the one-parameter version:
b. Parameters for the two-parameter version:
c. Why are the two versions of the method needed?

Programming Exercises
1. (12 points) Recall that LinkedBinarySearchTree is not a balanced tree. In the Asn12 main program, instantiate a LinkedBinarySearchTree object and insert the following Integers in this order: 40, 22, 32, 42, 25, 35, 45, 50, 55, 60. Draw the resulting tree here:
2. (5 points) Print out the tree from #1. Note that it is simply printed in order using an in-order iterator.
3. (15 points)
a. Write the findMin() method in LinkedBinarySearchTree.
b. Write findMax().
c. Write removeMax().
Hint: use findMax() and removeElement() to write removeMax().
4. (6 points) The LinkedBinarySearchTree implementation is not balanced. Suppose we wanted to implement an AVL tree. (Although we won’t get that far.) We would need to calculate the balance factor of a node. Write the method called getBalanceFactor(BinaryTreeNode<T> node). It will use getHeight to calculate the balance factor of a node.
5. (2 points) Write a method called isBalanced that uses getBalanceFactor to determine if a node is balanced. Recall that a balance factor of 2 or greater, or of -2 or smaller, is unbalanced.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

1. In the downloaded code, six different classes and interfaces include the word “tree.” List them.
a. BinarySearchTreeADT
b. BinarySearchTreeList
c. BinaryTreeADT
d. BinaryTreeNode
e. LinkedBinarySearchTree
f. LinkedBinaryTree

2. Which two from question #1 are interfaces?
a. BinaryTreeADT
b. BinarySearchTreeADT

3. Of the two interfaces from question #2, which one is the parent?
a. BinaryTreeADT

4. Of the four classes in question #1, which one…
a. represents a node in a tree?
i. BinaryTreeNode

b. represents a tree that doesn’t necessarily keep elements ordered?
i. LinkedBinaryTree

c. represents a tree that keeps its elements ordered?
i. BinarySearchTreeList

d. represents a list that is implemented with a tree?
BinarySearch...

By purchasing this solution you'll be able to access the following files:
Solution.docx and Solution.zip.

50% discount

Hours
Minutes
Seconds
$45.00 $22.50
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Data Structures and Algorithms Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats