Questions
Java Program Sequential Search You are given a sequence of n integers S and a sequence...

Java Program

Sequential Search

You are given a sequence of n integers S and a sequence of different q integers T. Write a program which outputs C, the number of integers in T which are also in the set S. Do not use any import sort packages.

Input: In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers are given.

Output: Print C in a line.

Constraints

  • n ≤ 10000
  • q ≤ 500
  • 0 ≤ an element in S ≤ 109
  • 0 ≤ an element in T ≤ 109

Sample Input 1

5
1 2 3 4 5
3
3 4 1

Sample Output 1

3

Sample Input 2

3
3 1 2
1
5

Sample Output 2

0

Sample Input 3

5
1 1 2 2 3
2
1 2

Sample Output 3

2

In: Computer Science

1. Show the red-black tree that result after successively inserting the keys 1, 2, 5, 15,...

1. Show the red-black tree that result after successively inserting the keys 1, 2, 5, 15, 4, 7, 8, 14, 11 into an initially empty red-black tree.

Show each step whenever you change a node’s color or make a rotation, mark your operations clearly.

In: Computer Science

Which property of secure hash functions—one-way, weak collision-resitance, or strong collision-resistance—make them useful in the context...

  1. Which property of secure hash functions—one-way, weak collision-resitance, or strong collision-resistance—make them useful in the context of password security?
  2. What is a password dictionary? Can it be used to improve password security?
  3. What is the motivation for limiting the password age? In particular, why would you enforce a maximum age? Why would you want to set a minimum age?

In: Computer Science

In terms of Cybersecurity, discuss about your Comprehensive Information Security and Privacy Program (500 Word)

  1. In terms of Cybersecurity, discuss about your Comprehensive Information Security and Privacy Program (500 Word)

In: Computer Science

Write a ADT called in minStack that provides the following methods: • push() // inserts an...

Write a ADT called in minStack that provides the following methods:

• push() // inserts an element to the “top” of the minStack

• pop() // removes the last element that was pushed on the stack

• top () // returns the last element that was pushed on the stack

• min() // returns the minimum value of the elements stored so far

In: Computer Science

write value of PI(3.14159) in IEEE-754 single-precision format

write value of PI(3.14159) in IEEE-754 single-precision format

In: Computer Science

PLEASE CODE IN JAVA In this assignment you will write a program in that can figure...

PLEASE CODE IN JAVA

In this assignment you will write a program in that can figure out a number chosen by a human user. The human user will think of a number between 1 and 100. The program will make guesses and the user will tell the program to guess higher or lower.

                                                                  Requirements

The purpose of the assignment is to practice writing functions. Although it would be possible to write the entire program in the main function, your solution should be heavily structured. The main function must look like this:

public static void main(String[] args) {

       do {

                playOneGame();

       } while (shouldPlayAgain());

}

The playOneGame function should have a return type of void. It should implement a complete guessing game on the range of 1 to 100.

The shouldPlayAgain function should have a boolean return type. It should prompt the user to determine if the user wants to play again, read in a character, then return true if the character is a ‘y’, and otherwise return false.

In addition, you should implement the helper functions getUserResponseToGuess, and getMidpoint. They should be invoked inside your playOneGame function.

getUserResponseToGuess. This function should prompt the user with the phrase “is it <guess>? (h/l/c): “ with the value replacing the token <guess>. It should return a char. The char should be one of three possible values: ‘h’, ‘l’, or ‘c’. It should have the following signature:

                        public static char getUserResponseToGuess(int guess)

getMidpoint. This function should accept two integers, and it should return the midpoint of the two integers. If there are two values in the middle of the range then you should consistently chose the smaller of the two. It should have the following signature:

                         public static int getMidpoint(int low, int high)

In: Computer Science

What is O(g(n)) for the following method? What sorting algorithm is this? /*Function to sort array...

What is O(g(n)) for the following method? What sorting algorithm is this? /*Function to sort array using ??? sort*/ void sort(int arr[]) { int n = arr.length; for (int i = 1; i < n; ++i) { int key = arr[i]; int j = i - 1; /* Move elements of arr[0..i-1], that are greater than key, to one position ahead of their current position */ while (j >= 0 && arr[j] > key) { arr[j + 1] = arr[j]; j = j - 1; } arr[j + 1] = key; } }

In: Computer Science

Normalisation (13 marks) The table below has basic information about Sales staff and their sales for...

Normalisation

The table below has basic information about Sales staff and their sales for a small appliance sales chain. It shows the employee, the items they sell as well as which store they work in.

SALES(Cost, Emp_Name, Emp_ID , Make, Grade , Price, Serial_No, Commission, Store _Address, Date, Store _Phone, Model)

The following functional dependencies apply and there are no redundancies present:

Store_Address -> Store_Phone
Grade -> Commission
Emp_ID -> Store _Address
Serial_No -> Model, Make
Emp_ID , Serial_No -> Date, Retail_Price Serial_No ->Wholesale_Price

Emp_ID -> Grade Emp_ID -> Emp_Name

3.1​ ​Find the Primary Key of the SALES relation.
3.2​ Decompose the SALES relation into 3NF. Show the final schema in full with all primary keys and

foreign keys mark appropriately.3.3​ The following FD also holds true:

Store_Phone-> Store_Address

Which relation in your decomposition would it map to? Test that relation to show that it is still in 3NF. Show your working.

In: Computer Science

Relational Modelling (20 marks) For the relation: R (A, B, C, D, E, F, G) The...

Relational Modelling

For the relation:
R (A, B, C, D, E, F, G)

The following functional dependencies hold: F -> D

G -> B
C -> D
F -> C, E B -> F
A -> F, G

2.1​ Use Inference rules to find the ​minimal b​ asis.

2.2​ Determine the ​primary key​ of the relation.

2.3​ Based on this key, determine if the relation R is in BCNF. Explain your answer in terms of the FDs and the key.

2.4​ If the relation R is not in 3NF or BCNF, then decompose the relation to 3NF/BCNF.

In: Computer Science

Divide and Conquer (Strassen’s Matrix Multiplication) Given two square matrices A and B of size n...

Divide and Conquer (Strassen’s Matrix Multiplication)

Given two square matrices A and B of size n x n each, find their multiplication matrix.

Naive Method
Following is a simple way to multiply two matrices.               

void multiply(int A[][N], int B[][N], int C[][N]) {

    for (int i = 0;   i < N; i++) {

        for (int j = 0; j < N; j++) {

            C[i][j] = 0;

            for (int k = 0; k < N; k++) {

                C[i][j] += A[i][k]*B[k][j];

            }

        }

    }

}

Time Complexity of above method is O(N3).

Divide and Conquer
Following is simple Divide and Conquer method to multiply two square matrices.
1) Divide matrices A and B in 4 sub-matrices of size N/2 x N/2 as shown in the below diagram.
2) Calculate following values recursively. ae + bg, af + bh, ce + dg and cf + dh.

Implement Strassen’s algorithm in Java / Python as indicated above.. in multiplying two square matrices of size n x n

Submit your solution online (BB), with the generated output

In: Computer Science

A mobile phone service provider has three different subscription packages for its customers: Package A: For...

A mobile phone service provider has three different subscription packages for its customers:

Package A: For $39.99 per month 450 minutes are provided. Additional minutes are
$0.45 per minute.

Package B: For $59.99 per month 900 minutes are provided. Additional minutes are
$0.40 per minute.

Package C: For $69.99 per month unlimited minutes provided.


Write a program that calculates a customer’s monthly bill. It should ask which package
the customer has purchased and how many minutes were used. It should then display
the total amount due.

Input Validation: Be sure the user only selects package A, B, or C.                                          

Assume 30 day month(Billing Cycle). Maximum Minutes is 43200.

Quality of craftsmanship is part of the grading.

===============================================================================

In: Computer Science

========================================================================= A software company sells a package that retails for $99. Quantity discounts are given according...

=========================================================================

A software company sells a package that retails for $99. Quantity discounts are given
according to the following table.
Quantity Discount
10–19 20%
20–49 30%
50–99 40%
100 or more 50%
Write a program that asks for the number of units sold and computes the total cost of
the purchase.
Input Validation: Make sure the number of units is greater than 0.

=========================================================================

the pseudo code is:

There comes situations in real life when we need to make some decisions and based on these decisions, we decide what should we do next. Similar situations arises in programming also where we need to make some decisions and based on these decision we will execute the next block of code. Decision making statements in programming languages decides the direction of flow of program execution.

Decision making structures require that the programmer specify one or more conditions to be evaluated or tested by the program selection construct, along with a statement or statements to be executed if the condition is determined to be true, and optionally, other statements to be executed if the condition is determined to be false.

When a customer purchases some quantity of our software package, we need to make a decision about how much discount to apply to the purchase. Our program will need to evaluate at least 4 to 5 conditions to determine which discount to apply.

We will use a decision making structure that can evaluate at test for five(5) possible conditions along with a statement to apply the discount if the condition is determined to be true.

Since we have multiple conditions to evaluate, we shall select to implement the if-else-if ladder construct which has the following syntax:

if (condition)
statement;
else if (condition)
statement;
.
.
else
statement;
=========================================================================
declare const for price
double const PRICE(99.00);

declare variables
int qty, double totalCost, discount

prompt user for qty

validate data & determine discount

if( qty <= 0 ) cout<<"Invalid Value\n"

else if( qty < 20 ) discount = 0.20

.
.
else discount = 0.50

compute totalCost

display results

----------------------------------------------------------------------------

In: Computer Science

In java processing 3, write a program that draws a circle. The center of the circle...

In java processing 3, write a program that draws a circle. The center of the circle would be first point on the canvas where the mouse is pressed on it. While the mouse is pressed, the circle can be drawn by moving the mouse cursor farther than the first point that mouse was pressed (circle center). As soon as the code is run, a timer at the bottom of the canvas should start working. Also, the radius of the circle cannot be more than 0.1 of the width of the canvas. If the player draws a large circle, the message "This is too big!" will be shown on the canvas. Still player can fix it and get back to game by moving the mouse towards the center of the circle (the point that first mouse was pressed on) and resume the game.

In: Computer Science

Briefly describe how switch operates.

Briefly describe how switch operates.

In: Computer Science