Questions
Let A[1..n] be an array of distinct positive integers, and let t be a positive integer....

  1. Let A[1..n] be an array of distinct positive integers, and let t be a positive integer.

    (a) Assuming that A is sorted, show that in O(n) time it can be decided if A contains two distinct elements x and y such that x + y = t.
    (b) Use part (a) to show that the following problem, re- ferred to as the 3-Sum problem, can be solved in O(n2) time:
    1. 3-Sum

      Given an array A[1..n] of distinct positive integers, and a positive integer t, determine whether or not there are three distinct elements x, y, z in A such that x+y+z = t.


If applicable, please give the algorithm (pseudocode/description) and analyze its running time to show that it meets the required bound.

In: Computer Science

A big problem of the blocking behavior of /dev/random is that blocking can lead to denial...

A big problem of the blocking behavior of /dev/random is that blocking can lead to denial of service attacks. Therefore, it is recommended that we use /dev/urandom to get random numbers. To do that in our program, we just need to read directly from this device file. The following code snippet shows how:

#define LEN 16 // 128 bits
unsigned char *key = (unsigned char *) malloc(sizeof(unsigned char)*LEN);

FILE* random = fopen("/dev/urandom", "r"); fread(key, sizeof(unsigned char)*LEN, 1, random);

fclose(random);

Please modify the above code snippet to generate a 256-bit encryption key. Please compile and run your code; print out the numbers and include the screenshot in the report.

In: Computer Science

Develop the following code in such a manner that it shoulde be having extra 3 attempts(for...

Develop the following code in such a manner that it shoulde be having extra 3 attempts(for wrong answrs) for all questions if the user entered wrong answer · for ex: If the user entered correct answer for first question #then 3 attempts will be carried to next questions. If the user entered 3 times wrong answer in 1st question itself means it sholud display as no more attempts and you got o out of 3

code....................

score=0
total_attempts=3
def question1(total_attempts,score):
print('What colors are apples?\na) Red/Green\nb) Orange\n')
answer1=input('enter answer: ')
if(answer1=='a'):
score=score+1
else:
print('try again')
attempts-=1
if attempts<=0:
print(' No More Attempts')
else:
question1(total_attempts,score)
return attempts,score
def question2 (total_attempts,score):
print('What colors are bananas?\na) Red/Green\nb) Yellow\n')
answer1=input('enter answer: ')
if(answer1=='b'):
score=score+1
else:
print('try again')
attempts-=1
if attempts<=0:
print(' No More Attempts')
else:
question2(attempts,score)
return attempts,score
def question3 (total_attempts,score):
print('What is the color of your hair?\na) Red/Green\nb) Black\n')
answer1=input('enter answer: ')
if(answer1=='b'):
score=score+1
else:
print('try again')
attempts-=1
if attempts<=0:
print(' No More Attempts')
else:
question3(total_attempts,score)
return attempts,score
def questions():
kk=question1(total_attempts,score)
if attempts>0:
hh=question2(kk[0],kk[1])
if attempts>0:
q=question3(hh[0],hh[1])
print('score= ',q[1])

python

In: Computer Science

Provide an in-depth and detailed explanation describing how the virtual page size of a memory system...

Provide an in-depth and detailed explanation describing how the virtual page size of a memory system might affect the performance of cache when the virtual page size is very large and then when it is very small.

In: Computer Science

Java Program 1Use a loop to add up the odd numbers between 100 and 200. 2Use...

Java Program

1Use a loop to add up the odd numbers between 100 and 200.

2Use a loop to determine if a number is prime. Recall: a number is prime if its only factors are 1 and itself.

3. Nested Loops:

}Write a nested loop that finds the largest prime number smaller than 125.

In: Computer Science

In Java create a simple class named student with the following properties: id age gpa credit...

In Java create a simple class named student with the following properties:

  • id

  • age

  • gpa

  • credit hours accomplished

Also, create the following methods:

  • Constructors

  • Getters and setters

In: Computer Science

Write a program (polygon.py) that asks the user to enter the number of sides in a...

Write a program (polygon.py) that asks the user to enter the number of sides in a regular polygon. For example, an equilateral triangle is a regular 3-sided polygon, a square is a regular 4-sided polygon, and a pentagon is a regular 5-sided polygon. If a user enters a number of sides between 3 and 25, inclusive, draw the polygon and wait for the user to click on the screen to quit the program. If the user enters a number less than 3 or greater than 25, tell them the number of sides must be between 3 and 25, and quit the program

Python.

In: Computer Science

-create a magic 8 ball program in JavaScript - use a loop to ask for the...

-create a magic 8 ball program in JavaScript
- use a loop to ask for the question
- use a random number to get the answer let randAnswer=Math.round(Math.round()*10);
- must have at least 10 different answers
-Must use either elseif or switch statement for answer
-must output both answer and user input to console
- the program should repeat indefinitely until either blank input, or cancel is selected

Bug in jsbin.com

Please don't use HTML thanks

In: Computer Science

What is the foreign key that creates a relationship between the Book and Publisher entities?

What is the foreign key that creates a relationship between the Book and Publisher entities?

In: Computer Science

Write a java code to demonstrate the File IO. Your code should get the following information...

Write a java code to demonstrate the File IO.

Your code should get the following information from the user.

• Get a file name fname for output

• Get number of data (numbers) (N) you want to process from the user

• Get N numbers from the users through keyboard and store them in an array

• Get M (How many numbers to read from file)

• (Or)You are free to use same N for M (use N for both purposes)

You have to define two methods:

1) To write the numbers from the array into the file fname

2) To read numbers from the file fname, store them in an array, and compute average of the numbers. The method should display the numbers from the array and the average value.

In: Computer Science

Given any positive integer n, the hailstone sequence starting at n is obtained as follows. You...

Given any positive integer n, the hailstone sequence starting at n is obtained as follows. You write a sequence of numbers, one after another. Start by writing n. If n is even, then the next number is n/2. If n is odd, then the next number is 3n + 1. Continue in this way until you write the number 1.

For example, if you start at 7, then the next number is 22 (3 × 7 + 1). The next number after 22 is 11.

  • The hailstone sequence starting at 7 is [7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1] and its length is 17.

  • The hailstone sequence starting at 6 is [6, 3, 10, 5, 16, 8, 4, 2, 1] and its length is 9.

  • The hailstone sequence starting at 1 is [1] and its length is 1.

The Assignment

Write and test a C++ program that reads a number n from the standard input (after giving a suitable prompt) and then writes the following information on the standard output:

  1. the entire hailstone sequence starting at n, all on one line, with the numbers separated by spaces;

  2. the length of the hailstone sequence that starts with n;

  3. the largest number in the hailstone sequence that starts with n;

  4. an indication of whether the hailstone sequence that starts with n contains a number that is greater than 1000.

  5. the length of the longest hailstone sequence that starts with a number from 1 to n;

  6. the starting number of the longest hailstone sequence that starts with a number from 1 to n;

  7. the largest number that occurs in any hailstone sequence that starts with a number from 1 to n.

  8. the start value, from 1 to n, of the hailstone sequence that contains largest number reported in the previous step.

For this program, use loops. Do not use recursion. Use type int for all of the integers. Do not use any of

  • arrays.
  • call-by-reference,
  • any features of the C++ Standard Template Library,
  • default parameters,
  • global or static variables

The main function must not contain any loops. You can use the <cstdio>, <iostream> and <algorithm> libraries for this assignment.

The output needs to be sensible and easy to read, not just numbers. It must follow the general template below, with all numeric results lined up (approximately) vertically. Each part of the output should be on a separate line. Parts in black are written by the program.

  What number shall I start with?  7
  The hailstone sequence starting at 7 is:
  7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
  Sequence length:                                      17
  Largest number:                                       52
  Contains a number >1000?                              no
  Greatest length starting with 1 to 7:                 17
  Start value of sequence of length 17:                  7
  Largest value in a sequence starting with 1 to 7:     52
  Start value of sequence containing 52:                 7

In: Computer Science

In this program we are going to utilize multiple classes to demonstrate inheritance and polymorphism. We...

In this program we are going to utilize multiple classes to demonstrate inheritance and polymorphism. We will be creating a base class for our game character. The base class will be LifeForm. We will have derived classes of Human, Dragon, and Unicorn.

LifeForm will have the following attributes:

  • hitPoints – range 0 to 100
  • strength – range 0 to 18

You will need to provide a default constructor that initializes these attributes as follows:

  • strength – 15
  • hitPoints – 100

You will need to provide a getter and setter for each of these variables. When the attribute has a range, the setter method should not allow a value outside that range. For example, if the setHitPoints(points) is called with points = -1, the attribute should NOT be changed. The variables should be private. Please provide a toString method which will return a String containing the values in these variables.

In your Human, Dragon and Unicorn classes you will need variables to hold the character name, weapon, and magic values. Values will be as follow:

Weapon

Magic Amount

Human

Sword or Dagger

0-50

Dragon

Fire or Ice

0-100

Unicorn

Horn or Charm

100-500

You will need to provide getters and setters for each of these private variables. Again, they should not allow values not in the table. You also need to provide a constructor for all of the variables, both the ones in the derived class and the ones in the base class.

Please provide a toString method that returns the type of character, the name, the weapon, the magic amount and the values from base class, call the toString() from the base class.

Create a driver class that allows the user to create a random set of characters. These should be of type Human, Dragon and Unicorn. These should be stored in an ArrayList of LIfeForm.    You should prompt the user for entries and create three characters of each class type and store them in the ArrayList. Once you have added the three characters. Print the characters from the ArrayList using your toString methods.

Example output: (Italics indicate user input)

Enter Lifeform 1:

Enter Lifeform Type: human

Enter Lifeform Name: Jon Snow

Enter hit points: 10

Enter strength: 5

Enter weapon: sword

Enter magic: 25

Enter Lifeform 2:

Enter Lifeform Type: unicorn

Enter Lifeform Name: Sparkles

Enter hit points: 0

Enter strength: 18

Enter weapon: charm

Enter magic: 300

Enter Lifeform Type: dragon

Enter Lifeform Name: Smaug

Enter hit points: 0

Enter strength: 18

Enter weapon: ice

Enter magic: 99

The available life forms are: ↵

Lifeform [hitPoints=10, strength=5, type=human]Human [name=jon snow, weapon=sword, magic=25]↵

Lifeform [hitPoints=0, strength=18, type=unicorn]Unicorn [name=sparkles, weapon=charm,magic=300]↵

Lifeform [hitPoints=0, strength=18, type=dragon]Dragon [name=smaug, weapon=ice, magic=99]↵

Grading Criteria (total 100 points):

Follows coding standards

10

Properly inputs all data

20

Properly creates minimum of 4 separate files using inheritance correctly

20

Properly creates ArrayList of Lifeform

15

Properly uses polymorphism to call toString from the ArrayList

20

Outputs are neat and easily read

15

In: Computer Science

Add a header to the lab with "YourName's List Of Countries" Using JS, inject an ordered...

  1. Add a header to the lab with "YourName's List Of Countries"
  2. Using JS, inject an ordered list into the div with the class "content"
  3. Give your new ordered list the class "countries"
  4. Design the following function to run on the click of a button from the index page
  5. Select 25 random countries from your list by writing a separate function that makes use of Math.random
    • You may need to explore how to do this by looking it up at MDN
  6. Make sure the selection is unique
  7. Using a .forEach or a .map function, inject a new list item for each country into the ol from #3
  8. Display the name of each country in a normal font weight
  9. Display the country code for each in a bold font weight
  10. Log the unselected countries to your console

Extra Credit (0.5 per)

  • Make sure your random countries display in alphabetical order OR
  • Make sure your countries are definitely not in alphabetical order
  • Guarantee a given country cannot appear twice in any given click of the button (point 7 but really do it)
  • Use JS to attach an event listener rather than using the onclick attribute on a button

Here is the link w/country codes:

https://www.iban.com/country-codes

In: Computer Science

Write a Java program for slidsender and slidreiver 1. Start the program 2. Get the frame...

Write a Java program for slidsender and slidreiver

1. Start the program

2. Get the frame size from the user

3. To create the frame based on the user

4. To send frames to server from the client

5. If your frames reach the server it will send ACK signal to client otherwise it will send NACK signal to

6. Stop the program

In: Computer Science

You want to test two different web page layouts to see which one performs better (this...

You want to test two different web page layouts to see which one performs better (this is known as an A/B test).

  1. What would you measure to determine which one is better - in other words, what is your metric of success?
  2. Assuming you've already designed the two web pages, how would you run this test?

In: Computer Science