Computers and Technology

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.

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 21:00, calmicaela12s
The mode is generally used when delivering a presentation to an need now
Answers: 1
image
Computers and Technology, 23.06.2019 12:00, anamatiascamaja
If you embed a word table into powerpoint, what happens when you make edits to the embedded data? a. edits made to embedded data change the data in the source file; however, edits made to the source file will not be reflected in the embedded data. b. edits made to embedded data will change the data in the source file, and edits made to the source file will be reflected in the embedded data. c. edits made to embedded data don't change the data in the source file, nor will edits made to the source file be reflected in the embedded data. d. edits made to embedded data don't change the data in the source file; however, edits made to the source file will be reflected in the embedded data.
Answers: 1
image
Computers and Technology, 23.06.2019 23:30, ayjahj
What can you prevent issues related to downloading content form the internet
Answers: 1
image
Computers and Technology, 24.06.2019 03:30, ava1018
The footer area of a web page generally houses which website feature? terms of use web page content business name or title menu headings
Answers: 1
Do you know the correct answer?
Java code for simple operations on binary search trees where keys are integers. Assume you already h...

Questions in other subjects:

Konu
Mathematics, 22.07.2021 19:20
Konu
Mathematics, 22.07.2021 19:20