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, 22.06.2019 15:10
David is in week 3 of his current ashford course and has a paper due by monday night at midnight. he has finished everything but the concluding paragraph. as he boots up his computer to work on it, he sees a flash across the screen and then the screen goes black. he begins to panic as he tries desperately to turn the laptop back on. david should have saved his work on what kind of portable device?
Answers: 2
question
Computers and Technology, 22.06.2019 20:00
Amanda needs to create an informative print brochure for her local library’s fundraiser dinner. what critical detail must she have before she starts designing the brochure?
Answers: 1
question
Computers and Technology, 23.06.2019 19:30
Amitha writes up a one-page summary of a novel during her summer internship at a publishing company. when she reads over the page, she realizes she used the word “foreshadow” seven times, and she would like to reduce the repetition. which tool would best amitha solve this problem?
Answers: 3
question
Computers and Technology, 24.06.2019 13:30
Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. the program should output the average high, average low, and the highest and lowest temper- atures for the year. your program must consist of the following functions: a. function getdata: this function reads and stores data in the two- dimensional array. b. function averagehigh: this function calculates and returns the average high temperature for the year. c. function averagelow: this function calculates and returns the aver- age low temperature for the year. d. function indexhightemp: this function returns the index of the highest high temperature in the array. e. function indexlowtemp: this function retur
Answers: 3
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, 15.01.2020 01:31
Questions on the website: 13722367