Implement two methods, find() and replace() relating to Binary Search Trees. Both of these methods must be recursive functions. The signatures for the functions must be:
/* This method takes a tree node and a key as an argument and returns the tree node if the key is found and returns null if the key is not found. */ BST find(BST T, char key)
/* This method takes a tree node and a key as an argument and inserts the tree node if the key is already in the tree it does not insert the node. */ BST insert(BST T, char key)
You will also implement the preOrder(), inOrder(), and postOrder() tree traversal methods. These methods must also be recursive functions. The input for this program will be from the keyboard and accept single-character keys, labeled 'A' - 'Z'.
Rules:
1) You cannot delete any code in the BST class, adding code is okay.
2) All 5 methods MUST be RECURSIVE. No credit is given if a method is not recursive, even if it works correctly.
3) Do not assume any maximum length for any input string.
4) Do not need to test for an empty string or null case.
5) You are not allowed to add any arrays or ArrayLists or any Java built-in (ADTs), such as Lists, Sets, Maps, Stacks, Queues, Deques, Trees, Graphs, Heaps, etc. or add any class that inherits any of those ADTs.
6) The use of Java Generics is also not allowed.
Starter code which must be used:
import java.util.Scanner; // Import the Scanner class
public class BST {
public char key;
public BST left;
public BST right;
public BST(char c) {
key = c;
left = null;
right = null;
}
public static BST find(BST T, char key) {
// put your solution here
}
public static BST insert(BST T, char key) {
// put your solution here
}
public static void preOrder(BST T) {
// put your solution here
}
public static void inOrder(BST T) {
// put your solution here
}
public static void postOrder(BST T) {
// put your solution here
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
BST t = null;
String stream = input.nextLine();
for (int i = 0; i < stream.length(); i++)
t = insert(t, stream.charAt(i));
System.out.print("Preorder: ");
preOrder(t);
System.out.println();
System.out.print("Inorder: ");
inOrder(t);
System.out.println();
System.out.print("Postorder: ");
postOrder(t);
System.out.println();
System.out.println("Enter a character to search for: ");
char c = input.nextLine().charAt(0);
if (find(t, c) == null)
System.out.println("The character " + "'" + c + "' was not
found.");
else
System.out.println("The character " + "'" + c + "' was
found.");
}
In: Computer Science
On Android Studio, create a 4 function calculator. The only buttons you need are 0-9, *, /, +, -, a clear, and enter button. Use StringTokenizer or String.split for the calculator code.
In: Computer Science
Write a function which lets the user enter English words. The user can keep entering English words as long as the user has not entered the word “exit”. Once the user enters “exit” the function will return and print the list of all distinct words starts with English alphabets. Like: A: Ali, apple, … B: Bob, book … until Z. Write a python program for this question. Use main function.
In: Computer Science
assume n = 2^100. consider the following problem. given an unsorted list of size n you can choose to sort it or not first. after this step, you get m queries q1, q2, ... qm. one by one of the form "is qi in the list?" Describe whether you would sort and what algorithm you would use if 1.) m= 10, and 2) m = 1000
In: Computer Science
Can you please explain loop invariant for Heapsort, in which Min-Heapify and Build-Min-Heap are correct
In: Computer Science
state the input and output of the traveling salesman problem. give the best lower bound on length of optimal tour and prove
In: Computer Science
please use C++
Create a class named Byte that encapsulates an array of 8 Bit objects. The Byte class will provide the following member functions:
Byte - word: Bit[8] static Bit array defaults to all Bits false
+ BITS_PER_BYTE: Integer16 Size of a byte constant in Bits; 8
+ Byte() default constructor
+ Byte(Byte) copy constructor
+ set(Integer): void sets Bit to true
+ clear(): void sets to 0
+ load(Byte): void sets Byte to the passed Byte
+ read(): Integer16 returns Byte as Integer
+ place(Integer): Bit Return Bit& at passed Base2 place
+ NOT(): Byte returns this Byte with its bits not'ed
+ AND(Byte): Byte returns this Byte and'ed with passed Byte
+ OR(Byte): Byte returns this Byte or'ed with passed Byte
+ NAND(Byte): Byte returns this Byte nand'ed with passed Byte
+ NOR(Byte): Byte returns this Byte nor'ed with passed Byte
+ XOR(Byte): Byte returns this Byte xor'ed with passed Byte
+ XNOR(Byte): Byte returns this Byte xnor'ed with passed Byte
In: Computer Science
List the policies thst a small business woupd need to develop. Include in each of these policies what its contents would address. Provide a summarry of the business, its operations, and a list of the major risks the policies are to address
In: Computer Science
In: Computer Science
In C++
Define enumeration data type menuItemName with enumerators of PlainEgg, BaconAndEgg, Muffin, FrenchToast, FruitBasket, Cereal, Coffee, and Tea.
Use an array, menuList, of the struct menuItemType, with tree components: menuItem of type menuItemName, menuPrice of type double, and Count of type int.
Write a program to help a local restaurant automate its breakfast billing system. The program should do the following:
a. Show the customer the different breakfast items offered by the restaurant.
b. Allow the customer to select more than one item from the menu.
c. Calculate and print the bill
Assume that the restaurant offers the following breakfast items (the price of each item is shown to the right of the item):
Plain Egg$1.45
Bacon and Egg$2.45
Muffin$0.99
French Toast$1.99
Fruit Basket$2.49
Cereal$0.69
Coffee$0.50
Tea$0.75
Use an array, menuList, of the struct menuItemType, with three components: menuItem of enummenuItemName as described above, menuPrice of type double, and Count of type int. Your program must contain at least the following functions:
● Function showMenu: This function shows the different items offered by the restaurant and tells the user how to select the items.
● Function printCheck: This function calculates and prints the check. (Note that the billing amount should include a 5% tax.)
A sample output is:
Welcome to Johnny’s Restaurant
Bacon and Egg1$2.45
Muffin1$0.99
Coffee2$1.00
Amount Total$4.44
Tax$0.22
Amount Due$4.66
In: Computer Science
For the Boolean function F = x + yz’+ x’z
In: Computer Science
1. Load the cpus dataset from the MASS package.
Use syct, mmin , mmax , cach , chmin, chmax as the predictors
(independent variables) to predict performance (perf)
Perform the best subset selection in order to choose the best
predictors from the above predictors.
What is the best model obtained according to Cp, BIC, and adjusted
R2?
Show some plots to provide evidence for your answer, and report the
coefficients of the best model obtained for each criterion.
Repeat using forward stepwise selection and also using backward
stepwise selection. How does your answer compare to the best subset
results?
In: Computer Science
You want to identify the purpose of a malware and possible damages that it has done to a computer network, after the executable file is discovered. Explain step-by-step approach that you will follow to reverse engineer the executable file by using static analysis tools. List all the tools that you will use and what type of information you will be able to gather by using that tool.
In: Computer Science
Must be written in C++ in Visual studios community
In this lab, you will modify the Student class you created in a previous lab. You will modify one new data member which will be a static integer data member. Call that data member count. You also add a static method to the Student class that will display the value of count with a message indicating what the value represents, meaning I do not want to just see a value printed to the screen.
Change main so that it calls this new method towards the end of the program. Call the method using the static syntax; do not use one of the instances of the Student class.
You will also need to change the Student constructor so that it increments the new data member you added, count.
Explain why you get the value it displays. Use codes below.
FIRST CODE
#include <iostream>
#include "Student.h"
using namespace std;
int main()
{
Student rich(2);
rich.DisplayStudent();
Student mary(3);
mary.DisplayStudent();
return 0;
}
SECOND CODE
#include "Student.h"
Student::Student(int numGrades)
{
quanity = numGrades;
grades = new int[numGrades];
name = "rich";
grades[0] = 88;
grades[1] = 96;
}
Student::~Student()
{
delete[] grades;
}
void Student::DisplayStudent()
{
cout << "Grades for " << name << endl;
for (int index = 0; index < quanity; index++)
{
cout << *(grades + index) << endl;
}
}
THIRD CODE
#pragma once
#include <string>
#include <iostream>
using namespace std;
class Student
{
public:
Student(int numGrades);
~Student();
void DisplayStudent();
private:
string name;
int* grades;
int quanity;
};
In: Computer Science
Write a function matchSuit() that simulates repeatedly drawing a pair of playing cards from a shuffled deck (of 52 cards) until the pair of cards share the same suit (or you run out of cards). The function should return the total number of cards drawn. Use a while loop. To draw each card, call the drawCard function you wrote above.
In: Computer Science