Arrange the following binary tree types in increasing order of height with the worst-case height of each type.
Binary Tree
Full Binary Tree
Complete Binary Tree
Binary Search Tree
Balanced Binary Tree
In: Computer Science
Create a dynamic array-based Queue ADT class in C++ that contains enqueue(Inserts newElement at the back ) and dequeue(Removes the frontmost element ). If the size of the array is equal to the capacity a new array of twice the capacity must be made.
The interface is shown:
class Queue {
private:
int* elements;
unsigned elementCount; // number of elements in the queue
unsigned capacity; // number of cells in the array
unsigned frontindex; // index the topmost element
unsigned backindex; // index where the next element will be placed
public:
// Description: Constructor
Queue();
// Description: Inserts newElement at the back (O(1))
void enqueue(int newElement);
// Description: Removes the frontmost element (O(1))
// Precondition: Queue not empty
void dequeue();
// Description: Returns a copy of the frontmost element (O(1))
// Precondition: Queue not empty
int peek() const;
// Description: Returns true if and only if queue empty (O(1))
bool isEmpty() const;
};
Thanks!
In: Computer Science
Powerball. In this assignment you are to code a program that selects 20 random non-repeating positive numbers (the Powerball Lottery numbers), inputs three numbers from the user and checks the input with the twenty lottery numbers. The lottery numbers range from 1 to 100. The user wins if at least one input number matches the lottery numbers.
As you program your project, demonstrate to the lab instructor displaying an array passed to a function. Create a project titled Lab6_Powerball. Declare an array wins of 20 integer elements.
Define the following functions:
Hint: Array elements are assigned 0, which is outside of lottery numbers' range, to distinguish elements that have not been given lottery numbers yet.
Passing an array as a parameter and its initialization is done similar to the code in this program.
#include <iostream>
using std::cout; using std::endl; using std::cin;
// initializes the array by user input
void fillUp(int [], int);
int main( ) {
const int arraySize=5;
int a[arraySize];
fillUp(a, arraySize);
cout << "Echoing array:\n";
for (int i = 0; i < arraySize; ++i)
cout << a[i] << endl;
}
// fills upt the array "a" of "size"
void fillUp(int b[], int size) {
cout << "Enter " << size << " numbers: ";
for (int i = 0; i < size; ++i)
cin >> b[i];
}Hint: Looking for the match is similar to looking for the minimum number in this program.
#include <iostream>
using std::cout; using std::endl; using std::cin;
int main(){
const int arraySize=5;
int numbers[arraySize]; // array of numbers
// entering the numbers
cout << "Enter the numbers: ";
for(int i=0; i < arraySize; ++i)
cin >> numbers[i];
// finding the minimum
int minimum=numbers[0]; // assume minimum to be the first element
for (int i=1; i < arraySize; ++i) // start evaluating from second
if (minimum > numbers[i])
minimum=numbers[i];
cout << "The smallest number is: " << minimum << endl;
}
Hint: Use srand(), rand() and time() functions that we studied earlier to generate appropriate random numbers from 1 to 100 and fill the array. Before the selected number is entered into the array wins, call function check() to make sure that the new number is not already in the array. If it is already there, select another number.
The pseudocode for your draw() function may be as follows:
declare a variable "number of selected lottery numbers so far",
initialize this variable to zero
while (the_number_of_selected_elements is less than the array size)
select a new random number
call check() to see if this new random number is already in the array
if the new random number is not in the array
increment the number of selected elements
add the newly selected element to the array
#include <iostream>
using std::cout; using std::endl; using std::cin;
// initializes the array by user input
void fillUp(int [], int);
int main( ) {
const int arraySize=5;
int a[arraySize];
fillUp(a, arraySize);
cout << "Echoing array:\n";
for (int i = 0; i < arraySize; ++i)
cout << a[i] << endl;
}
// fills upt the array "a" of "size"
void fillUp(int b[], int size) {
cout << "Enter " << size << " numbers: ";
for (int i = 0; i < size; ++i)
cin >> b[i];
}
The pseudocode your function main() should be as follows:
main(){
declare array and other variables
assign(...) // fill array with 0
draw(...) // select 20 non-repeating random numbers
iterate three times
entry(...) // get user input
use check () to compare user input against lottery numbers
if won state and quit
printOut(...) // outputs selected lottery numbers
}
Note: A program that processes each element of the array separately (i.e. accesses all 20 elements of the array for assignment or comparison outside a loop) is inefficient and will result in a poor grade.
Note 2: For your project, you should either pass the array size (20) to the functions as a parameter or use a global constant to store it. Hard-coding the literal constant 20 in function definitions that receive the array as a parameter is poor style. It should be avoided.
In: Computer Science
Why is security so important to wireless networks? Give two
examples of defense measures that should be taken to enhance
wireless security.
In: Computer Science
Write a class called CombineTwoArraysAlternating that combines two
lists by alternatingly taking elements, e.g.
[a,b,c], [1,2,3] -> [a,1,b,2,c,3].
You must read the elements of the array from user input by reading
them in a single line, separated by spaces, as shown in the examples
below.
Despite the name of the class you don't need to implement this class
using arrays. If you find any other way of doing it, as long as it
passes the test it is ok.
HINTS:
You don't need to use any of my hints. As long as you pass the test
you can write the code any way you want.
I used:
String [] aa = line.split("\\s+");
to split the String contained in the variable called 'line' into
strings separated by at least one white space character. For
example if line is "hello world how are you?" the previous statement
populates array aa in such a way that
aa[0] is: "hello"
aa[1] is: "world"
aa[2] is: "how"
aa[3] is: "are"
aa[4] is: "you?"
I used the method Arrays.toString from java.util.Arrays to print
arrays. For example the following lines of code:
String line = "hello world how are you?";
String [] aa = line.split("\\s+");
//Arrays.toString(aa) takes array aa and returns a nicely formatted String
System.out.println(Arrays.toString(aa));
produce the following output:
[hello, world, how, are, you?]
In: Computer Science
For Cloud Database Encryption Technology Based on Combinatorial Encryption
You are required to research and report on this topic according to the Detail of Question below.
A. understand in order to present three main parts:
1. Summary:
o Provide a 200-300 word summary of the paper under review, from the background to the results being presented, and further work proposed. Please do NOT copy the abstract into this space!
2. Main points:
o The main issues as you see them.
o This is different than the summary.
3. Strengths and Weaknesses:
o Provide some critical analysis of the paper under review, positive and/or negative.
In: Computer Science
What do you understand by pre- and post-conditions
of a function?
Write the pre- and post-conditions to axiomatically specify the
following
functions:
(a) A function takes two floating point numbers representing the
sides of
a rectangle as input and returns the area of the
corresponding
rectangle as output.
(b) A function accepts three integers in the range of -100 and +100
and
determines the largest of the three integers.
(c) A function takes an array of integers as input and finds the
minimum
value.
(d) A function named square-array creates a 10 element array
where
each all elements of the array, the value of any array element
is
square of its index.
(e) A function sort takes an integer array as its argument and
sorts the
input array in ascending order.
In: Computer Science
Suppose you turn on a system and everything is dead- no lights, nothing on the monitor screen, and no spinning fan or hard drive. You verify the power to the system works, all power connections and power cords are securely connected, and all pertinent switches are turned on. you are now sure the power supply has gone bad. Explain in 2 to 3 paragraph how you will go about to buy and install a new power supply and making sure the problem is resolved.
In: Computer Science
Create and display an XML file in Android studio that has
-One edittext box the does NOT use material design
-One edittext box that DOES use material design
Provide a “hint” for each, and make sure the string that comprises the hint is referenced from the strings.xml file.
Observe the differences in how the hints are displayed.
Here is sample code for a material design editText:
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_price1Text"
android:layout_width="80dp"
android:layout_height="40dp"
>
<EditText
android:id="@+id/price1Text"
android:importantForAutofill="no"
tools:targetApi="o"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="6"
android:inputType="numberDecimal"
android:hint="@string/hint_text"
/>
</android.support.design.widget.TextInputLayout>
It requires this to be added to the build.gradle Module:app
implementation 'com.android.support:design:28.0.0'
Take a screenshot, Make sure the screenshot clearly shows the two different ways that the hints are displayed.
In: Computer Science
"""
CS 125 - Intro to Computer Science
File Name: CS125_Lab1.py
Python Programming
Lab 1
Name 1: FirstName1 LastName1
Name 2: FirstName2 LastName2
Description: This file contains the Python source code
for deal or no deal.
"""
class CS125_Lab1():
def __init__(self):
# Welcome user to game
print("Let's play DEAL OR NO DEAL")
# Define instance variables and init board
self.cashPrizes = [.01, .50, 1, 5, 10, 50, 100, 250, 500, 1000,
5000, 10000, 100000, 500000, 1000000]
self.remainingPrizesBoard = []
self.gameOver = False
self.offerHistory = []
self.initializeRandomPrizeBoard()
"""----------------------------------------------------------------------------
Prints the locations available to choose from
(0 through numRemainingPrizes-1)
----------------------------------------------------------------------------"""
def printRemainingPrizeBoard(self):
# Copies remaining prizes ArrayList into prizes ArrayList (a temp
ArrayList)
prizes = []
for prize in self.remainingPrizesBoard:
prizes.append(prize)
prizes.sort()
# TODO 1: Print the prizes in the prize ArrayList. All values
should be on
# a single line (put a few spaces after each prize) and add a new
line
# at the end (simple for loop);
# NOTE: '${:,.2f}'.format(num) is the python
# equivalent to the Java df.format(num) DecimalFormat class, which
allows
# you to print a decimal num like 5.6 as $5.60.
"""----------------------------------------------------------------------------
Generates the banks offer. The banker algorithm computes the
average
value of the remaining prizes and then offers 85% of the
average.
----------------------------------------------------------------------------"""
def getBankerOffer(self):
pass
# TODO 2: Write code which returns the banker's offer as a
double,
# according to the description in this method's comment above.
#----------------------------------------------------------------------------
# Takes in the selected door number and processes the result
#----------------------------------------------------------------------------
def chooseDoor(self, door):
# TODO 6: Add the current bank offer (remember, we have a
method
# for to obtain the current bank offer - call
self.getBankerOffer())
# to the our offerHistory.
if door == -1:
pass
# This block is executed when the player accepts the banker's
offer. Thus the game is over.
# TODO 3: Set the gameOver variable to true
# Inform the user that the game is over and how much money they
accepted from the banker.
# Print the offer history (there is a method to call for
this).
else:
pass
# This block is executed when the player selects one of the
remaining doors.
# TODO 4: Obtain the prize behind the proper door and remove the
prize from the board
# Print out which door the user selected and what prize was behind
it (this prize is now gone)
# If only one prize remaining, game is over!!!
if len(self.remainingPrizesBoard) == 1:
pass
# This block is executed when there is only one more prize
remaining...so it is what they win!
# TODO 5: Set the gameIsOver variable to true
# Let the user know what prize they won behind the final
door!
# Print the offer history (there is a method to call for this).
"""----------------------------------------------------------------------------
This method is called when the game is over, and thus takes as
a
parameter the prize that was accepted (either from the banker's
offer
or the final door).
Prints out the offers made by the banker in chronological
order.
Then, prints out the money left on the table (for example, if
the
largest offer from the banker was $250,000, and you ended up
winning
$1,000, whether from a later banker offer or from the last
door,
then you "left $249,000 on the table).
----------------------------------------------------------------------------"""
def printOfferHistory(self, acceptedPrize):
# Print out the history of offers from the banker
# TODO 7: Print out the banker offer history (will need to loop
through
# your offerHistory member variable) and find the max offer
made.
# Print one offer per line, like:
# Offer 1: $10.00
# Offer 2: $5.00
# .....
maxOffer = 0
print("\n\n\n***BANKER HISTORY***")
# TODO 8: If the max offer was greater than the accepted prize,
then print out
# the $$$ left out on the table (see the example in this method's
header above).
# Otherwise, congratulate the user that they won more than the
banker's max
# offer and display the banker's max offer.
"""
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////DO NOT EDIT ANY PORTIONS OF METHODS
BELOW///////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
"""
"""----------------------------------------------------------------------------
Processes all the code needed to execute a single turn of the
game
----------------------------------------------------------------------------"""
def playNextTurn(self):
print("-----------------------------------------------------------------------")
# Print out remaining prizes
print("There are " + str(len(self.remainingPrizesBoard)) + " prizes
remaining, listed in ascending order: ")
self.printRemainingPrizeBoard()
# Display all prize doors
print("\nThe prizes have been dispersed randomly behind the
following doors:")
for i in range(0, len(self.remainingPrizesBoard)):
print(str(i), end=" ")
print("")
# Print out banker's offer and ask user what to do
print("\nThe banker would like to make you an offer
of...................." +
'${:,.2f}'.format(self.getBankerOffer()))
print("")
# Get selection from user and choose door
promptStr = "What would you like to do? Enter '-1' to accept the
banker's offer, " + "or select one of the doors above (0-" +
(str(len(self.remainingPrizesBoard)-1)) + "): "
selectedDoorNum = int(input(promptStr))
if selectedDoorNum >= -1 and selectedDoorNum <
len(self.remainingPrizesBoard): # Make sure valid sel.
self.chooseDoor(selectedDoorNum)
else:
print(str(selectedDoorNum) + " is not a valid selection.")
print("")
print("")
'''----------------------------------------------------------------------------
Basically, a getter method for the gameIsOver method. The
client
will continually call playNextTurn() until gameIsOver()
evaluates
to true.
----------------------------------------------------------------------------'''
def gameIsOver(self):
return self.gameOver
'''----------------------------------------------------------------------------
Copies the constant prizes (from an array) into a temporary
array
and uses that array to populate the initial board into the
member
variable 'remainingPrizesBoard'.
----------------------------------------------------------------------------'''
def initializeRandomPrizeBoard(self):
# Start with a fresh board with nothing in it
self.remainingPrizesBoard = []
# Copies cashPrizes array into prizes ArrayList (a temp
ArrayList)
prizes = []
for prize in self.cashPrizes:
prizes.append(prize)
# Randomizes prizes into remainingPrizesBoard
while len(prizes) > 0:
from random import randint
i = randint(0, len(prizes)-1)
self.remainingPrizesBoard.append(prizes[i]) # Copy into our
"board"
del prizes[i]
# Debug print which will show the random board contents
#for p in self.remainingPrizesBoard:
# print('${:,.2f}'.format(p), end=" -- ")
#print("")
In: Computer Science
Write a JAVA program that generates three random numbers from 1 to 6, simulating a role of three dice. It will then add, subtract and multiply these two numbers. It will also take the first number to the power of the second and that result to the power of the third. Display the results for each calculation. Please note that the sample run is based on randomly generated numbers so your results will be different.
Sample run:
6 + 2 + 5 = 13
6 - 2 – 5 = -1
6 * 2 * 5 = 60
6 to the power of 2 to the power of 5 = 60,466,176
A second sample run:
2 + 3 + 5 = 10
2 – 3 - 5 = -6
2 * 3 * 5 = 30
2 to the power of 3 to the power of 5 = 32,768
In: Computer Science
JAVASCRIPT: -
Please create an object (grade) with 10 names and 10 grades.
- Create a method (inputGrade) that can put a name and a grade to
the grade object.
- Create another method (showAlltheGrades) to show all the grade in
that object.
- Create the third method (MaxGrade) that can display the maximum
grade and the student name.
- Using “prompt” and inputGrade method input 10 student names and
their grades.
- Display all the grades and names by using showAlltheGrades
method.
NOTE: Make sure to use the push() method when adding
elements to the arrays. Please post the code and a screenshot of
the output. Thanks!
[Reference JavaScript code]
<html>
<body>
<script>
// Declare a class
class Student {
// initialize an object
constructor(grade, name) {
this.grade=grade;
this.name=name; }
//Declare a method
detail() {
document.writeln(this.grade + " " +this.name)
}//detail
}//class
var student1=new Student(1234, "John Brown");
var student2=new Student(2222, "Mary Smith");
student1.detail();//call a method
student2.detail();
</script>
</body>
</html>
In: Computer Science
Determine the subnet mask for the following IP addresses. Please show your work how you got the answer so i can understand how to do it.
10.55.64.8 need 80 subnets
192.168.1.x /26 – subnet mask
172.16.10.2 / 18 – subnet mask
172.16.10.4 / 20- subnet mask
In: Computer Science
A department employs up to thirty employees, but an employee is employed by one department. For each employee you need to store unique employee Id, name, address and salary. Departments are identified by department Id and also have a name. Some employees are not assigned to any department. A division operates many departments, but each department is operated by one division. An employee may be assigned at the most three projects, and a project may have at the most six employees assigned to it. A project may have at least one employee assigned to it. Each project is identified by unique name and has a budget. A project can be related to other projects. There can be many related projects. One of the employees manages each department, and each department is managed by only one employee. One of the employees runs each division, and each division is run by only one employee. For each division, store unique Id and name.
REQUIRED:
a) Design a conceptual diagram from the above information.
b) Develop a logical data model for the database.
c) Explain the importance of data modelling.
In: Computer Science
Show that the external path length epl in a 2-tree with m external nodes satisfies epl≤ (1/2)(m^2+m−2). Conclude that epl≤ (1/2n)(n+ 3) for a 2-tree with n internal nodes.
In: Computer Science