In C++, dealing with Binary Search trees. Implement search, insert, removeLeaf, and removeNodeWithOneChild methods in BST.h. BST.h code below
#include <iostream>
#include "BSTNode.h"
using namespace std;
#ifndef BST_H_
#define BST_H_
class BST {
public:
BSTNode *root;
int size;
BST() {
root = NULL;
size = 0;
}
~BST() {
if (root != NULL)
deepClean(root);
}
BSTNode *search(int key) { // complete this method
}
BSTNode *insert(int val) { // complete this method
}
bool remove(int val) { // complete this method
}
private:
void removeLeaf(BSTNode *leaf) { // complete this method
}
void removeNodeWithOneChild(BSTNode *node) { // complete this method
}
static BSTNode *findMin(BSTNode *node) {
if (NULL == node)
return NULL;
while (node->left != NULL) {
node = node->left;
}
return node;
}
static BSTNode *findMax(BSTNode *node) {
if (NULL == node)
return NULL;
while (node->right != NULL) {
node = node->right;
}
return node;
}
void print(BSTNode *node) {
if (NULL != node) {
node->toString();
cout << " ";
print(node->left);
print(node->right);
}
}
static int getHeight(BSTNode *node) {
if (node == NULL)
return 0;
else
return 1 + max(getHeight(node->left), getHeight(node->right));
}
static void deepClean(BSTNode *node) {
if (node->left != NULL)
deepClean(node->left);
if (node->right != NULL)
deepClean(node->right);
delete node;
}
public:
int getTreeHeight() {
return getHeight(root);
}
void print() {
print(root);
}
int getSize() {
return size;
}
};
#endifIn: Computer Science
For Humming code H(15,11), write a computer program for decoding, which outputs an error correction dictionary from received 15bits to corrected 11bits data or maps from input as the received 15bits to output as the corrected 11bits data. Demonstration outputs of the running program with explanation are required to show its correctness. Any computer programming language is acceptable. DETAILED DESCRIPTIONS MUST BE INCLUDED FOR THE CODE
In: Computer Science
In: Computer Science
Exercise 6 - Oscar nominated movies(Using python to solve it! please)
Write a bot that asks a user what movies they have seen. If they have not seen a movie, it tells them to watch that movie. The user can pick as many names as they want, but they will put all of the names in one input, which means the names will be in a single string rather than a list. Use the following list of movies:
In: Computer Science
Consider the following virtual page reference sequence: page 1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3. This indicates that these particular pages need to be accessed by the computer in the order shown. Consider each of the following 4 algorithm-frame combinations:
Print a copy of this page. For each of the 4 combinations, below, move from left to right as the virtual page numbers are requested in sequence. Put each virtual page into one of the frames by writing its number there (initially while empty frames remain, load them from top down). When all frames are already occupied by other pages, choose the right page to displace according to the applicable algorithm (LRU or FIFO) and mark the event with an F for Fault. (Do not count a fault when loading a missing page at a time when there is a frame unoccupied, in other words on the first 3 or 4 loads.) When finished, total the number of page faults and write it in where indicated.
Submit the printout. The assignment will be graded on 8 items: the 4 final page configuration figures at the extreme right (correct or incorrect), and the 4 page fault totals written (correct or incorrect). Please work carefully.
THREE Page Frames
Least-recently-used (LRU) method:
| 1 | 2 | 3 | 4 | 2 | 1 | 5 | 6 | 2 | 1 | 2 | 3 | ||||||||||||||||||||||||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
Number of page faults for LRU/3:
First-in-First-out (FIFO) method:
| 1 | 2 | 3 | 4 | 2 | 1 | 5 | 6 | 2 | 1 | 2 | 3 | ||||||||||||||||||||||||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
Number of page faults for FIFO/3:
FOUR Page Frames
Least-recently-used (LRU) method:
| 1 | 2 | 3 | 4 | 2 | 1 | 5 | 6 | 2 | 1 | 2 | 3 | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
Number of page faults for LRU/4:
First-in-First-out (FIFO) method:
| 1 | 2 | 3 | 4 | 2 | 1 | 5 | 6 | 2 | 1 | 2 | 3 | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
Number of page faults for FIFO/4:
In: Computer Science
1. Draw a structured flowchart or write structured pseudocode describing how to get from your home to your school. Include at least two decisions and two loops.
2. Draw a structured flowchart and write pseudocode that describes the process of guessing a number between 1 and 100. After each guess, the player is told that the guess is too high or too low. The process continues until the player guesses the correct number. Pick a number and have a fellow student try to guess it following the instructions.
In: Computer Science
Java
Starter Code:
|
import java.util.Scanner; Sample Output: Team Scores by quarter: Team 2 has won the game! |
In: Computer Science
Create a website with html about raccons, just a simple html model to build off of including multiple pages including a home, about us, and learn more page. Text filler not needed. Just the html structure.
In: Computer Science
In this problem you will need to read about the functions numpy.load and numpy.bincount. Store all answers in appropriate variables. numbers = np.load('randomints.npy')
Use only numpy functionality to carry out this part.
(a) Load the file randomints.npy into a numpy array. There are 100000 integers in this file and they are between 0 and 1000.
(b) Get a bincount array for the array loaded in the first part.
(c) Let M be the largest number of times an element occurs in the array.
What is the smallest number that occurs M times?
(d) What is the number of integers that occurred 111 times?
In: Computer Science
Given two integer arrays sorted in the ascending order, code the function SortArrays to merge them into one array in the descending order. You need to make sure if the values in the arrays are changed, it will still work. (25 points) #include using namespace std; void SortArrays (int a[], int b[], int c[], int size); void printArray(int m[], int length); const int NUM = 5; int main() { int arrA[NUM] = {-2, 31, 43, 55, 67}; int arrB[NUM] = {-4, 9, 11, 17, 19}; int result[2*NUM]; SortArrays(arrA, arrB, result, NUM); printArray(result, 2*NUM); return 0; } void SortArrays (int a[], int b[], int c[], int size) { } void printArray(int m[], int length) { for(int i = 0; i < length; i++) cout<< m[i]<<" "; cout<endl;
}
In: Computer Science
Write a single python file to perform the following tasks:
(a) Get dataset “from sklearn.datasets import load_iris”. Split the dataset into two sets: 20% of samples for training, and 80% of samples for testing.
NOTE 1: Please use “from sklearn.model_selection import
train_test_split” with “random_state=N” and “test_size=0.80”.
NOTE 2: The offset/bias column is not needed here for augmenting
the input features.
(b) Generate the target output using one-hot encoding for both the training set and the test set.
(c) Using the same training and test sets generated above, perform a polynomial regression (utilizing “from sklearn.preprocessing import PolynomialFeatures”) from orders 1 to 10 (adopting the weight-decay L2 regularization with regularization factor λ=0.0001) for classification (based on the
one-hot encoding) and compute the number of training and test samples that are classified correctly.
NOTE 1: The offset/bias augmentation will be automatically generated by PolynomialFeatures. NOTE 2: If the number of rows in the training polynomial matrix is less than or equal to the number of
columns, then use the dual form of ridge regression (Lecture 6). If not, use the primal form (Lecture 6).
Submit a single python file with filename “A2_StudentMatriculationNumber.py”. It should contain a function A2_MatricNumber that takes in an integer “N” as input and returns the following outputs in the following order:
X_train: training numpy feature matrix with dimensions (number_of_training_samples ⨯ 4). (1%)
X_test: test numpy feature matrix with dimensions (number_of_test_samples ⨯ 4). (1%)
y_train: training target numpy array (containing values 0, 1 and 2) of length
number_of_training_samples. (1%)
y_test: test target numpy array (containing values 0, 1 and 2) of length number_of_test_samples. (1%)
Ytr: one-hot encoded training target numpy matrix (containing only values 0 and 1) with dimension
(number_of_training_samples ⨯ 3). (1%)
Yts: one-hot encoded test target numpy matrix (containing only values 0 and 1) with dimension
(number_of_test_samples ⨯ 3). (1%)
Ptrain_list: list of training polynomial matrices for orders 1 to 10. Ptrain_list[0] should be polynomial
matrices for order 1 (size number_of_training_samples x 5), Ptrain_list[1] should be polynomial matrices for
order2(sizenumber_of_training_samplesx15),etc. (1.5%)
Ptest_list: list of test polynomial matrices for orders 1 to 10. Ptest_list[0] should be polynomial
matrices for order 1, Ptest_list[1] should be polynomial matrices for order 2, etc. (1.5%)
w_list: list of estimated regression coefficients for orders 1 to 10. w_list[0] should be estimated regression
coefficients for order 1, w_list[1] should be estimated regression coefficients for order 2, etc. (2%)
error_train_array: numpy array of training error counts (error count = number of samples classified incorrectly) for orders 1 to 10. error_train_array[0] is error count for polynomial order 1, error_train_array[1]
is error count for polynomial order 2, etc. (2%)
error_test_array: numpy array of test error counts (error count = number of samples classified
incorrectly) for orders 1 to 10. error_test_array[0] is error count for polynomial order 1, error_test_array[1] is error count for polynomial order 2, etc. (2%)
Please use the python template provided to you. Remember to rename both “A2_StudentMatriculationNumber.py” and “A2_MatricNumber” using your student matriculation number. For example, if your matriculation ID is A1234567R, then you should submit “A2_A1234567R.py” that contains the function “A2_A1234567R”. Please do NOT zip/compress your file. Because of the large class size, points will be deducted if instructions are not followed. The way we would run your code might be something like this:
>> import A2_A1234567R as grading
>> N = 10
>> X_train, X_test, y_train, y_test, Ytr, Yts, Ptrain_list,
Ptest_list, w_list, error_train_array, error_test_array =
grading.A2_A1234567R(N)
In: Computer Science
Java
Write a method that counts how many times one string appears in another string. The method takes three input parameters: two Strings and one Boolean. The Boolean value determines whether the words are allowed to overlap each other. For example:
When the method is called with input parameters (“balloon”, “oo”, false), it returns 1.
When the method is called with input parameters (“hh”, “hhhhhh”, true) returns 5.
When the method is called with input parameters (“cc”, “abcdefg”, true), returns 0.
In: Computer Science
Write a Fortran program that reads in two NxN matrices A & B, and prints their element-wise sum (A+B), element-wise difference (A-B), element-wise division (A/B), element-wise product (A*B), and their matrix product (matmul(A,B)), on the standard output.
In: Computer Science
the following question is based on the table information below.
Assume that the data is populated with records: CREATE TABLE teachers ( emp_id bigserial, first_name varchar(25), last_name varchar(50), school varchar(50), hire_date date, salary numeric); SELECT first_name, last_name, school, salary FROM teachers WHERE hiredate > '2008-01-01' ORDER BY last_name ASC;
Question 1) Will this query return an error?
Question 2) If there is an error, what is causing the error? if there is not an error, leave blank.
In: Computer Science