Please create a class named BST based on the information in the second screenshot. You don't have to modify the class Node. After that, please use the BST class and Node class to create a class BSTApp. Please make sure to use the same class name so that I don't get confused. Also, please make sure to use the following code as a starting point.  import java.util.*; public class BSTTest{ public static void main(String[] args) { // perform at least one test on each operation of your BST } private int[] randomArray(int size) { // remove the two lines int[] arr = new int[1]; return arr; } // the parameters and return are up to you to define; this method needs to be uncommented // private test() { // // } } Base of class Node public class Node { int key; Node left, right, parent; public Node() {} public Node(int num) { key = num; left = null; right = null; parent = null; } } Base of class BST import java.util.*; class BST { // do not change this private Node root; private ArrayList data; // DO NOT MODIFY THIS METHOD public BST() { root = null; data = new ArrayList(0); } // DO NOT MODIFY THIS METHOD public ArrayList getData() { return data; } // DO NOT MODIFY THIS METHOD public void inOrderTraversal() { inOrderTraversal(root); } // DO NOT MODIFY THIS METHOD private void inOrderTraversal(Node node) { if (node != null) { inOrderTraversal(node.left); data.add(node.key); inOrderTraversal(node.right); } } // search public boolean search(int target) { // remove this line return false; } // insert public Node insert(int target) { // remove this line return root; } // note: you may need to implement several supporting methods for delete public Node delete(int target) { // remove this line return root; } // you are welcome to add any supporting methods }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Please create a class named BST based on the information in the second screenshot. You don't have to modify the class Node. After that, please use the BST class and Node class to create a class BSTApp. Please make sure to use the same class name so that I don't get confused. Also, please make sure to use the following code as a starting point. 

import java.util.*;

public class BSTTest{
public static void main(String[] args) {
// perform at least one test on each operation of your BST

}

private int[] randomArray(int size) {
// remove the two lines
int[] arr = new int[1];
return arr;
}

// the parameters and return are up to you to define; this method needs to be uncommented
// private test() {
//
// }
}

Base of class Node

public class Node {
int key;
Node left, right, parent;

public Node() {}

public Node(int num) {
key = num;
left = null;
right = null;
parent = null;
}
}

Base of class BST

import java.util.*;

class BST {
// do not change this
private Node root;
private ArrayList<Integer> data;

// DO NOT MODIFY THIS METHOD
public BST() {
root = null;
data = new ArrayList<Integer>(0);
}

// DO NOT MODIFY THIS METHOD
public ArrayList<Integer> getData() {
return data;
}

// DO NOT MODIFY THIS METHOD
public void inOrderTraversal() {
inOrderTraversal(root);
}

// DO NOT MODIFY THIS METHOD
private void inOrderTraversal(Node node) {
if (node != null) {
inOrderTraversal(node.left);
data.add(node.key);
inOrderTraversal(node.right);
}
}

// search
public boolean search(int target) {
// remove this line
return false;
}

// insert
public Node insert(int target) {
// remove this line
return root;
}

// note: you may need to implement several supporting methods for delete
public Node delete(int target) {
// remove this line
return root;
}

// you are welcome to add any supporting methods
}

public class Node {
int key;
Node left, right, parent;
public Node () {}
public Node (int num) {
key = num;
left = null;
right = null;
parent = null;
}
}
The most important thing is that a node as an object has four attributes: key, left, right, parent. Key holds the
value of the node. Left and right refer to the left and right children nodes. Parent refers to the parent node.
To finish the design of your BST class, you will be working on the following attributes/methods:
Insert: This method accepts one parameter, the target value (an integer), and will add a new node with
that value into the Binary Search Tree. This method returns the root of the updated Binary Search Tree.
public Node insert(int target)
Search: This method accepts one parameter, the target value, and returns a boolean. If the target value is
found, this method returns true, otherwise false.
public boolean search(int target)
Delete: This method accepts one parameter, the target value, and will delete the node with the target
value if such a node exists. This method returns the root of the updated Binary Search Tree. You might
need to create a set of other supporting methods for the delete method.
public Node delete(int target)
The above methods should NOT be declared as static, and you are required to use the given Node class.
Transcribed Image Text:public class Node { int key; Node left, right, parent; public Node () {} public Node (int num) { key = num; left = null; right = null; parent = null; } } The most important thing is that a node as an object has four attributes: key, left, right, parent. Key holds the value of the node. Left and right refer to the left and right children nodes. Parent refers to the parent node. To finish the design of your BST class, you will be working on the following attributes/methods: Insert: This method accepts one parameter, the target value (an integer), and will add a new node with that value into the Binary Search Tree. This method returns the root of the updated Binary Search Tree. public Node insert(int target) Search: This method accepts one parameter, the target value, and returns a boolean. If the target value is found, this method returns true, otherwise false. public boolean search(int target) Delete: This method accepts one parameter, the target value, and will delete the node with the target value if such a node exists. This method returns the root of the updated Binary Search Tree. You might need to create a set of other supporting methods for the delete method. public Node delete(int target) The above methods should NOT be declared as static, and you are required to use the given Node class.
Given a binary search tree with non-negative values, find the minimum absolute difference between values of
any two nodes.
Example:
Input:
4
8.
Output: 1
Explanation:
The minimum absolute difference is 1, which is the difference between 7 and 8.
Your solution class to this problem should be named as "BSTApp". The method that solves this problem should
be declared static and named “minDiff". minDiff takes one parameter, root of a binary search tree:
static public int minDiff(Node root)
You should also create a main method under this class, in which at least two test cases need to be given to test
“minDiff' method by printing necessary information. For instance, the printed messages of an example are:
The traverse gives a BST as 2, 4, 7, 8.
The minimum absolute difference is 1.
Transcribed Image Text:Given a binary search tree with non-negative values, find the minimum absolute difference between values of any two nodes. Example: Input: 4 8. Output: 1 Explanation: The minimum absolute difference is 1, which is the difference between 7 and 8. Your solution class to this problem should be named as "BSTApp". The method that solves this problem should be declared static and named “minDiff". minDiff takes one parameter, root of a binary search tree: static public int minDiff(Node root) You should also create a main method under this class, in which at least two test cases need to be given to test “minDiff' method by printing necessary information. For instance, the printed messages of an example are: The traverse gives a BST as 2, 4, 7, 8. The minimum absolute difference is 1.
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY