one can tell by comparing nodes between two given trees whether
they relate to each other, by having a reflected symmetric
structure (i.e. being mirror images of each other), having
identical structure, or not being related at all. In this
assignment, you are asked to implement the following
features.
Hard-code some paired lists of integers.
Build binary search trees from each list
Print the binary search trees in the three orders discussed in
class.
Determine if the two binary search trees are identical, mirrors of
each other, or neither
Remove a number in each tree at random and compare the tree pair
again
Further, since the methods of the binary search tree class have been presented with recursive function calls, it is now up to you to implement these recursive functions with iterative loops.
You must write a Class Node, a class TreeChecker and a class
BinarySearchTree. For Java users, they must implement the following
interfaces respectively:
public interface INode {
//Getter of node data
T getData();
//Setter of node data
void setData(T data);
INode getLeftChild() ;
void setLeftChild(INode leftChild) ;
INode getRightChild() ;
void setRightChild(INode rightChild);
}
public interface ITree {
void setRoot(INode root);
INode getRoot();
void preorder(); // print tree in a preorder
traversal
void inorder(); // print tree in an inorder
traversal
void postorder(); // print tree in a postorder
traversal
INode insert(INode root, T data); // insert data into tree
INode remove(INode root, T data); //search/remove node
with data
T search(INode root, T data); //search and return data
if it exists
INode getMax(INode root); //return node with maximum
value of subtree
INode getMin(INode root); //return node with minimum
value of subtree
}
public interface ITreeChecker {
boolean isMirror(ITree root1, ITree root2); // check if two trees
are mirror
// images
boolean isSame(ITree root1, ITree root2); // check if
two trees are identical
}
Then if you could run the code in this main class.
public class Main {
public static void main(String[] args) throws
IOException {
// build a tree for the following
lists
// int array1[] = [4,1,9,12,3,2,8,7,16,20,13,11];
// int array2[] =
[4,1,9,12,3,2,8,7,16,20,13,11];
//add more examples here
Bst1 = new
BinarySearchTree();
Bst2 = new
BinarySearchTree();
//more trees for each example
treeChecker = new TreeChecker();
//build each BST
//print each tree with each order of traversal
//compare bst1 and bst2 as
mirror images with tree checker
If(treeChecker.isMirror(bst1,
bst2))
Print messages
saying the trees are mirrors of each other
// compare bst1 and bst2 as being
identical with tree checker
Else If(treeChecker.isSame(bst1,
bst2))
Print messages
saying the trees are identical to each other
Else
Print message
saying the trees are not related
//randomly remove a number from
each tree
//compare bst1 and bst2 again
// more code here to finish regarding comparing the other BST
pairs…
}
In: Computer Science
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void clrScreen(int lines){
int i = 0;
for( i = 0; i < lines; ++i ){
printf("\n");
}
return;
}
void printRules(void){
printf("\t|*~*~*~*~*~*~*~*~*~ How to Play ~*~*~*~*~*~*~*~*~*~|\n");
printf("\t| This is a 2 player game. Player 1 enters the |\n");
printf("\t| word player 2 has to guess. Player 2 gets a |\n");
printf("\t| number of guesses equal to twice the number |\n");
printf("\t| of characters. EX: If the word is 'example' |\n");
printf("\t| player 2 gets 14 guesses. |\n");
printf("\t|*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~|\n");
clrScreen(10);
return;
}
//------------------------------------------------------------------------------------------------------------
/* /\DO NOT MODIFY ABOVE THIS LINE /\*/
void playGame(){
int correctGuess = 1;
char garbage;
clrScreen(40);
printRules();
printf("Player 1: Enter a word smaller than 50 characters: ");
clrScreen(40);
if( -1 == correctGuess ){
printf("CoNgRaTuLaTiOnS!!!!!! You figured out the word!!!\n");
printf("\t\t%s\n");
} else {
printf("You didn't figure out the word.....it was %s\n");
printf("Better luck next time!\n");
}
printf("Press 'enter' to continue to main menu.\n");
scanf("%c", &garbage);
}
int menu(void){
int loop = 1;
while( loop ){
clrScreen(40);
printf("*~*~*~*~*~*~*~*~*~*~Welcome to Hangman!*~*~*~*~*~*~*~*~*~*~\n");
printf("\t1.) Play the game\n");
printf("\t2.) Quit\n");
printf("Please make a selection: ");
}
}
/*
hangman game RULES:
2 player game
player 1
enter a word for player 2 to guess
enter a number of guesses player 2 gets to have. It must be at least 2x as big
as the number of letters in the word.
For example, if you enter the word 'sky' you must give the player at least 6 guesses.
player 2
try to guess the word player 1 has entered.
you get X number of guesses
*/
int main(void){
return 0;
}
//In c programming language
//please help me finish this hangman program. Thank you.
In: Computer Science
PYTHON LANGUAGE
PLEASE DO NUMBER 5 ONLY
"""
# 1. Based on Textbook R6.28
# Create a table of m rows and n cols and initialize with 0
m = 3
n = 4
# The long way:
table = []
for row in range(m) :
table.append([0]*n)
# The short way:
# 2. write a function to print the table in row, column
format,
# then call the function
'''
# using index
def printTable(t):
for i in range(len(t)) : # each i is an index, i = 0,1,2
for j in range(len(t[i])) : # j = 0,1,2,3
print(t[i][j], end=' ')
print()
'''
# without index:
def printTable(t):
for row in t :
for col in row :
print(col, end=' ')
print()
print()
printTable(table)
# what does the following print?
for i in range(m):
for j in range(n):
table[i][j] = i + j
printTable(table)
'''
Answer:
print: from these index values:
0 1 2 3 [0,0] [0,1] [0,2] [0,3]
1 2 3 4 [1,0] [1,1] [1,2] [1,3]
2 3 4 5 [2,0] [2,1] [2,2] [2,3]
'''
# 3. copy table to table2
table2 = copy.deepcopy(table)
'''
table2 = table => table2 is another reference to the same mem
location
table2 = table.copy() => shallow copy
only copy the 1D list (outer list) of references,
which has row1 - row4 references
table => [ row1 => [ , , , ]
row2 => [ , , , ]
row3 => [ , , , ]
row4 => [ , , , ]
]
'''
table[0][0] = -1 # will table2 be changed? No
printTable(table2)
# 4. fill elements of bottom row of table2 with -1's
# and all elements of left col of table2 with 0's
for i in range(len(table2[-1])) :
table2[-1][i] = -1
for i in range(len(table2)) :
table2[i][0] = 0
printTable(table2)
"""
"""
# 5. We start with a dictionary of student ids and
associated gpa's
d = {123:3.7, 456:3.8, 789:2.7, 120:2.8}
print(d)
# create a list of sid list and a tuple of gpa from d
# create a list of tuples (k,v) from d
# How do you construct a dictionary from a list of tuples?
# How do you construct a dictionary from the list of id and
gpa?
"""
In: Computer Science
Description Your program must start and keep dialog with the user. Please create the first prompt for the dialog. After that your program must accept the user’s response and echo it (output to screen) in upper case and adding the question mark at the end. The program must run endlessly until the user say “stop” in any combination of cases. Then you program must say “GOODBYE!” and quit. Example: HELLO, I AM THE PROGRAM Hi, I am Michael HI, I AM MICHAEL? Are you kidding? ARE YOU KIDDING?? I prefer to speak to somebody smarter I PREFER TO SPEAK TO SOMEBODY SMARTER? Stupid STUPID? You YOU? sToP! STOP!? stop GOODBYE!
In: Computer Science
What is Stuxnet and what are its real-world implications? Should your national government be concerned about the potential of a Stuxnet-like attack? Why or why not.
In: Computer Science
Implement (provide pseudocode) the 'A la Russe' algorithm which does not use arrays.
In: Computer Science
C programming language only!
a file is given that has comma-separated integers. the files contents are -1,-9,1,45,3,2,1,-1...
Create a function that takes as an input a filename and returns an array containing the list of integers in the file
In: Computer Science
((PYTHON))
Finish the calories_burned_functions.py program that we started in class. Take the original calories_burned program and rework it so that it uses two functions/function calls.
Use the following file to get your program started:
"""
''' Women: Calories = ((Age x 0.074) - (Weight x 0.05741) +
(Heart Rate x 0.4472) - 20.4022) x Time / 4.184 '''
''' Men: Calories = ((Age x 0.2017) + (Weight x 0.09036) + (Heart
Rate x 0.6309) - 55.0969) x Time / 4.184 '''
"""
#Declare Variable names and types
age_years = int(input())
weight_pounds = int(input())
heart_bpm = int(input())
time_minutes = int(input())
#Performing Calculations
calories_woman = ( (age_years * 0.074) - (weight_pounds * 0.05741)
+ (heart_bpm * 0.4472) - 20.4022 ) * time_minutes / 4.184
calories_man = ( (age_years * 0.2017) + (weight_pounds * 0.09036) + (heart_bpm * 0.6309) - 55.0969 ) * time_minutes / 4.184
#Print and format results in detail
print('Women: {:.2f} calories'.format(calories_woman))
print('Men: {:.2f} calories'.format(calories_man))
"""
#Here are the functions to this program
def calc_calories_woman(years, pounds, heartrate,
minutes):
return ( (age_years * 0.074) - (weight_pounds * 0.05741) +
(heart_bpm * 0.4472) - 20.4022 ) * time_minutes / 4.184
#This is the main part of the program
#------------------------------------------------------------------------------
#Prompt the user at the keyboard for the necessary information
age_years = int(input("Please enter your age: "))
weight_pounds = int(input("Please enter your weight: "))
heart_bpm = int(input("Please enter your heart rate: "))
time_minutes = int(input("Please enter the time: "))
#Calculate the calories
calories_woman = ( (age_years * 0.074) - (weight_pounds * 0.05741) + (heart_bpm * 0.4472) - 20.4022 ) * time_minutes / 4.184
calories_man = ( (age_years * 0.2017) + (weight_pounds * 0.09036) + (heart_bpm * 0.6309) - 55.0969 ) * time_minutes / 4.184
#Print the results
print('Women: {:.2f} calories'.format(calories_woman))
print('Men: {:.2f} calories'.format(calories_man))
In: Computer Science
Construct this program in C programming Please.
Using a do/while loop, your program will ask/prompt the user to enter in a positive value representing the number of values they wish to have processed by the program or a value to quit/exit. If the user enters in a 0 or negative number the program should exit with a message to the user indicating they chose to exit. If the user has entered in a valid positive number, your program should pass that number to a user defined function. The user defined function will use a for loop to compute an average value. The function will use the number passed to it to determine how many times it will prompt the user to supply a value. The user may enter in any number value positive, floating point or negative. The for loop will continue to prompt the user, calculating the average of the values entered. The function should return the calculated value to the calling function. The calling function using the do/while loop should print out the average and then repeat the process until the user enters in the signal to stop as described previously.
In: Computer Science
Database - Data Control Language
Exercise
Write few system and object privileges.
Create user with your name and grant above discussed system and object privileges to the user created. Revoke update and select from the user which you have created.
In: Computer Science
Sleeping Barber Problem where there is only 1 barber in the shop for x clients
function Customer()
acquire(mutex)
if num_waiting < num_chairs then
num_waiting + 1
release(customer)
release(mutex)
acquire(barber)
Cutmyhair()
else
release(mutex)
end
end
function Barber()
while not breaking
acquire(customer)
acquire(mutex)
num_waiting - 1
release(barber)
release(mutex)
Clipaway()
end while
end
QUESTION: come up with the pseudocode for the clipaway() and cutmyhair() methods so that each client pays for there haircut and the barber gives each client a customized haircut.
Any language.
thank you in advance !!!
In: Computer Science
Using C++
Many software applications use comma-separated values to store and transfer data.
In this program, you are asked to implement the movie_call function that will parse a string of the above structure into the corresponding movie name, rating, and movie length.
ex: In "movie name, rating, length", the movie name is "movie name", the rating is "rating", and the length of the movie is "lenght".
This is the code:
#include <iostream>
#include <string>
using namespace std;
/*
Replace the function body with appropriate statements to movie_call
a string of movie details into its corresponding movie name, rating,
and length.
*/
void movie_call (string movie, string& name, string& rating, string& length) {
int comma, comma1;
comma = movie.find(",");
name = movie.substr(0, comma);
movie = movie.substr(comma + 1);
comma1 = movie.find(",");
rating = movie.substr(0, comma1);
length = movie.substr(comma1 + 1);
}
int main() {
string movie_details;
cout << "Please enter information for one movie of your choice: ";
getline(cin, movie_details);
//Add appropriate statement(s) to call the movie_call function
//and display the name, rating, and length
return 0;
}
In: Computer Science
In: Computer Science
The home work is to do a survey comparing the following three
programming language:
COBOL , FOTRAN 77, and PASCAL regarding:
1- Character set.
2- Reserved(key) words and special symbols.
3- Simple data types and data structures used.
4- Control structures used (selection and loop
structures)
5- File structure used.
In: Computer Science
Which of the following is the key exchange that Eve and Mel might use to simultaneously agree on a large prime number and integer?
A. Quantum Prime
B. Prime-Curve
C. Diffie-Hellman
D. Elliptic Curve Diffie-Hellman
In: Computer Science