subject

Java code for simple operations on binary search trees where keys are integers. Assume you already have the following code and assume that the method bodies, even though not shown, are correct and implement the operations as we defined them in class.
public class BinarySearchTreeNode

{

public int key;

public BinarySearchTreeNode left;

public BinarySearchTreeNode right;

}

public class BinarySearchTree {

private BinarySearchTreeNode root;

public void insert(int key) { ... }

public void delete(int key) { ... }

public boolean find(int key) { ... }

}

(a) Add a method public int positiveKeySum() to the BinarySearchTree class that returns the sum of all non-negative keys in the tree. You will need an assistant/helper method.

(b) Add method public void deleteMax() to the BinarySearchTree class that deletes the maximum element in the tree (or does nothing if the tree has no elements).

(c) Add method public void printTree() to the BinarySearchTree class that iterates over the nodes to print then in decreasing order. So the tree... Produces the output "5 4 3 2 1". Note: You will need an assistant/helper method.

(d) Add method public void printPostorder() to the BinarySearchTree class that prints out the nodes of the tree according to a "postorder" traversal. So the tree... Produces the output "1 3 2 5 4". Note: You will need an assistant/helper method.

(e) You have a binary search tree. Consider a leave l. B is the set of keys in the path p of l including the leave l and the root of the tree. A is the set of keys to the left of the path p. C is the set of keys to the right of the path p. Is the following statement true or false? Given any element a in A; b in B; c in C; a ≀ b ≀ c. Justify your answer.

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 11:50
While preforming before operation pmcs, you notice the front right tire appears slightly under-inflated. what is the proper action?
Answers: 3
question
Computers and Technology, 23.06.2019 23:30
A. in packet tracer, only the server-pt device can act as a server. desktop or laptop pcs cannot act as a server. based on your studies so far, explain the client-server model.
Answers: 2
question
Computers and Technology, 24.06.2019 17:00
Anew author is in the process of negotiating a contract for a new romance novel. the publisher is offering three options. in the first option, the author is paid $5,000 upon delivery of the final manuscript and $20,000 when the novel is published. in the second option, the author is paid 12.5% of the net price of the novel for each copy of the novel sold. in the third option, the author is paid 10% of the net price for the first 4,000 copies sold, and 14% of the net price for the copies sold over 4,000. the author has some idea about the number of copies that will be sold and would like to have an estimate of the royal- ties generated under each option. write a program that prompts the author to enter the net price of each copy of the novel and the estimated number of copies that will be sold. the program then outputs he royalties under each option and the best option the author could choose. (use appropriate named constants to store the special values such as royalty rates and fixed royalties.
Answers: 1
question
Computers and Technology, 24.06.2019 17:50
Which of the following best describe how the depth-limited search works. a normal depth-first search is performed but the number of ply/depths is limited. a normal breadth-first search is performed but the number of ply/depths is limited. a normal breadth-first search is performed but values above a specific value will be ignored. a normal depth-first search is performed but values above a specific value will be ignored.
Answers: 1
You know the right answer?
Java code for simple operations on binary search trees where keys are integers. Assume you already h...
Questions
question
Mathematics, 03.12.2019 10:31
question
Chemistry, 03.12.2019 10:31
Questions on the website: 13722359