Please use the information on the first screenshot about a class BST and node class to implement a method named “randomArray” in the file named “BSTTest.java” that tests a specific sorting algorithm. This method will take one parameter: size of a randomly generated array (int): e.g., 10 This method will: Generate and return a random array of the length specified by the parameter The value range of each element should be between 0 and 1000 (inclusive) >>> randomArray(5). >>> [1, 2, 3, 7, 10]   Implement a method named “test” in the file named “BSTTest.java”. This method should take advantage of  the implemented randomArray and print out information as such: Testing of BST starts. Insert 3 Insert 2 Insert 5 Insert 100 Delete 3. The traverse gives a BST as 3, 5, 100 Testing of BST ends. Please note that the goal is not to manually code the printings of each line. Try your best to make this method as automatic as possible. There are no limits on what parameters this method shall accept or what it returns. However, please make sure to use the method to perform testing for at least two cases in your main method of BSTTest.java. Please use the following code as a base.  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() { // // } }

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

Please use the information on the first screenshot about a class BST and node class to implement a method named “randomArray” in the file named “BSTTest.java” that tests a specific sorting algorithm. This method will take one parameter:

  • size of a randomly generated array (int): e.g., 10

This method will:

  1. Generate and return a random array of the length specified by the parameter
  2. The value range of each element should be between 0 and 1000 (inclusive)

>>> randomArray(5).

>>> [1, 2, 3, 7, 10]

 

Implement a method named “test” in the file named “BSTTest.java”. This method should take advantage of  the implemented randomArray and print out information as such:

Testing of BST starts.

Insert 3

Insert 2

Insert 5

Insert 100

Delete 3.

The traverse gives a BST as 3, 5, 100

Testing of BST ends.

Please note that the goal is not to manually code the printings of each line. Try your best to make this method as automatic as possible. There are no limits on what parameters this method shall accept or what it returns. However, please make sure to use the method to perform testing for at least two cases in your main method of BSTTest.java.

Please use the following code as a base. 

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() {
//
// }
}

 

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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Array
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