
This assignment requires you to write a non-verbose input-driven java program for maintaining a binary search tree (BST) of integer elements (negative, zero or positive). The speciality of your BST will be that it
will record the frequency of occurrence for each integer element in it.
Actions provisioned on the BST. When your program is running, a user should be able to select one of the following actions to be performed on the BST.
1. Insert an element into the BST
2. Search for an element in the BST
3. Find the maximum element from the BST
4. Find the minimum element from the BST
5. Print the elements in the BST in preorder
6. Print the elements in the BST in postorder
7. Print the elements in the BST in inorder
8. Delete an element
Anything else to exit the program. The user will provide their choice of action on the BST, by entering one of the numbers between 1 to 8 that
correspond to their choice. For example, if the user wishes to insert an element, they will enter the number 1.
If the user wishes to print the inorder traversal of the tree, they will enter the number 7, and so on. Record the frequency for each element. A user may insert the same integer element into the BST more than once. An element will be recorded in a unique node in the BST. That node will also store the frequency of occurrence for the element. When a user asks to insert an element that is already present in the BST, its frequency will be incremented by 1 and no new node will be created in the BST. When an element with frequency more than 1 is asked to be deleted, its frequency will be decremented by 1.
At any point of time, the frequency of an element in the BST would denote the difference between the number of times it has been inserted into the BST and the number of times it has been deleted from the BST. When the number of times an element has been deleted equals the number of times it has been inserted, the frequency of occurrence of the element will become 0. That is when the BST node of the element would have to be deleted altogether from the BST. This will ensure that unused memory is freed by the program. User inputs. Your program will not receive any command-line input when you execute the program. However,
it will accept inputs from the user at run-time. Your program will ask for the following two types of inputs.
1. An action (any one out of the eight described above) to be performed on the BST
2. An integer element to be inserted to, searched for or deleted from the BST
When the program asks for any kind of input from the user, it will be non-verbose. In the rst case, there will be no menu printed before the user is prompted for the input. In the second case, there will be no description
printed about the input it is expecting. The user of the program will always know what input to provide when the program is expecting one.
[Hint: You may initially write the program in a verbose manner. Once you have tested the program and it is working well, you may turn o the verbose feature, particularly before submission. You may then comment
out all those System.out.print function calls that pertain to the verbose outputs.
Alternatively, you may consider including a feature that will turn o the verbose outputs from a single point in your code. This can be done using a boolean (static or member) flag variable such that all the user-friendly System.out.print function calls would be executed only if the flag is true.]
1
Printing an element. An element from the BST will always be printed along with its frequency.
For example,
if there is a node in the BST that contains the element −7, and its frequency is presently recorded as 2, the data in the node will be printed as
−7(2)
If the element (say 122) is not present in the BST, that will be reported as having the frequency 0. The output will look as follows.
122(0)
Searching an element. An element will be searched following the usual searching
frequency 0.
Inserting an element. An element to be inserted in a BST may or may not already be present in the BST.
If it is not present in the BST, a new leaf node will be created in the BST that will store the element with frequency 1. If the element is already in a node in the BST, inserting it again will only increment the currently
recorded frequency of the element by 1.
Deleting an element. An element to be deleted from a BST must have frequency ≥ 1. Otherwise, the deletion operation will fail. On deleting the element, the currently recorded frequency of the element will be
decremented by 1. If that brings down the frequency of the element to 0, the node for the element will then be deleted altogether from the BST.
Library or package allowed. You are only allowed to use the Scanner class of the java.util package.

Trending nowThis is a popular solution!
Step by stepSolved in 2 steps

- Write a python hangman program Modify your program so that the following functionality is added:1. Instead of selecting the word from a hard coded list, incorporate problem2 so that thelist is read from a file, then a word is randomly selected from this list.2. when the game ends, the following information should be outputted to a new file:● the word● the state of the hangman● if the user won or lostExample outputs:quokkaO\||You won!kangarooO\|/|/ \You lostarrow_forwardJava Program ASAP Please modify Map<String, String> morseCodeMap = readMorseCodeTable("morse.txt"); in the program so it reads the two text files and passes the test cases. Down below is a working code. Also dont add any import libraries in the program just modify the rest of the code so it passes the test cases. import java.io.BufferedReader;import java.io.FileReader;import java.io.IOException;import java.util.HashMap;import java.util.Map;import java.util.Scanner;public class MorseCodeConverter { public static void main(String[] args) { Map<String, String> morseCodeMap = readMorseCodeTable("morse.txt"); Scanner scanner = new Scanner(System.in); System.out.print("Please enter the file name or type QUIT to exit:\n"); do { String fileName = scanner.nextLine().trim(); if (fileName.equalsIgnoreCase("QUIT")) { break; } try { String text =…arrow_forwardThe Task This assignment requires you to write a non-verbose input-driven java program for m aint aining a binary search tree (BST) of integer elements (negative, zero or positive). The speciality of your BST will be that it will record the frequency of occurrence for each integer element in it. Actions provisioned on the BST. When your program is running, a user should be able to select one of the following actions to be performed on the BST. 1. Insert an element into the BST 2. Sear ch for an element in the BST 3. Find the maximum element from the BST 4. Find the minimum element from the BST 5. Print the elements in the BST in preorder 6. Print the elements in the BST in postorder 7. Print the elements in the BST in inorder 8. Delete an element Anything else to exit the program When the progr am is executed, the user will provide their choice of action on the BST, by entering one of the numbers between 1 to 8 that corre spond to their choice. For example, if the user wishes to insert…arrow_forward
- The program inserts a number of values into a priority queue and then removes them. The priority queue treats a larger unsigned integer as a higher priority than a smaller value. The priority queue object keeps a count of the basic operations performed during its lifetime to date, and that count is available via an accessor. In one or two places I have put statements such as op_count++;, but these are incomplete. We only count operations involved in inserting and removing elements, not auxiliary operations such as is_empty() or size() The class implements a priority queue with an unsorted vector. Your assignment is to re-implement the priority queue implementation using a heap built on a vector, exactly as we discussed in class. Leave the framework and public method interfaces completely unchanged. My original test program must work with your new class. You will have to write new private methods bubble_up and percolate_down. You should not implement heapify or heapsort. #include…arrow_forwardYou will create two programs. The first one will use the data structure Stack and the other program will use the data structure Queue. Keep in mind that you should already know from your video and free textbook that Java uses a LinkedList integration for Queue. Stack Program Create a deck of cards using an array (Array size 15). Each card is an object. So you will have to create a Card class that has a value (1 - 10, Jack, Queen, King, Ace) and suit (clubs, diamonds, heart, spade). You will create a stack and randomly pick a card from the deck to put be pushed onto the stack. You will repeat this 5 times. Then you will take cards off the top of the stack (pop) and reveal the values of the cards in the output. As a challenge, you may have the user guess the value and suit of the card at the bottom of the stack. Queue Program There is a new concert coming to town. This concert is popular and has a long line. The line uses the data structure Queue. The people in the line are objects…arrow_forwardRun the program to tell me there is an error, BSTChecker.java:3: error: duplicate class: Node class Node { ^ BSTChecker.java:63: error: class LabProgram is public, should be declared in a file named LabProgram.java public class LabProgram { ^ 2 errors This is my program, please fix it. import java.util.*; class Node { int key; Node left, right; public Node(int key) { this.key = key; left = right = null; } } class BSTChecker { public static Node checkBSTValidity(Node root) { return checkBSTValidityHelper(root, null, null); } private static Node checkBSTValidityHelper(Node node, Integer min, Integer max) { if (node == null) { return null; } if ((min != null && node.key <= min) || (max != null && node.key >= max)) { return node; } Node leftResult = checkBSTValidityHelper(node.left, min, node.key); if (leftResult != null) { return leftResult; } Node rightResult = checkBSTValidityHelper(node.right, node.key, max); if (rightResult != null) { return rightResult; }…arrow_forward
- Assume we have an IntBST class, which implements a binary search tree of integers. The field of the class is a Node variable called root that refers to the root element of the tree. 1) Write a recursive method for this class that computes and returns the sum of all integers less than the root element. Assume the tree is not empty and there is at least one element less than the root. 2) Write a recursive method that prints all of the leaves, and only the leaves, of a binary search tree. 3) Write a method, using recursion or a loop, that returns the smallest element in the tree.arrow_forwardAdd the following method in the BST class that returns aniterator for traversing the elements in a BST in preorder./** Return an iterator for traversing the elements in preorder */java.util.Iterator<E> preorderIterator()arrow_forwardNeed help making a java file that combines both linearSearch and binarySearch •Both search methods must use the Comparable<T> interface and the compareTo() method.•Your program must be able to handle different data types, i.e., use generics.•For binarySearch, if you decide to use a midpoint computation formula that is different fromthe textbook, explain that formula briefly as a comment within your code. //code from textbook //linearSearch public static <T> boolean linearSearch(T[] data, int min, int max, T target) { int index = min; boolean found = false; while (!found && index <= max) { found = data [index].equals(target); index++; } return found; } //binarySearch public static <T extends Comparable<T>> boolean binarySearch(T[] data, int min, int max, T target) { boolean found = false; int midpoint = (min + max)/2; if (data[midpoint].compareTo(target)==0)…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





