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 }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I have been posting the same questions but they always come with the same answer that does not use the starting code given below. Please make sure to use the following code as a starting point. 

Also, please make sure to use the same class name so that I don't get confused.

Please use the information in the screenshot to create a class called BST. The base of the code is given below. 

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.
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education