Question

In: Computer Science

What is the largest size n of a problem that can solve in 1 second, assuming...

What is the largest size n of a problem that can solve in 1 second, assuming that the algorithm to solve the problem takes sqrt(n) microseconds? (sqrt stands for square root)

1

10^(6)

10^(12)

10^(3)

How does the array arr = [8, 5, 3, 6, 10] look like after the second iteration (when j = 3) of the j loop on line 1 of the give pseudocode below?

insertion_sort.PNG

1 for j
2 do
3 // Insert A[j] into the sorted

// sequence A[1..j - 1] –1

5 while i > 0 and A[i] > key do

7. ii–1
8 A[i + 1] key

[5, 8, 3, 6, 10]

[3, 5, 5, 6, 10]

[8, 5, 3, 6, 10]

[3, 5, 8, 6, 10]

Solutions

Expert Solution

Answer 1 : The largest size n of a problem that can solve in 1 second is 10^(12) .

Explanation :

Given : Time taken by the algorithm to solve the problem = sqrt(n) microseconds

To find : Largest size n of a problem that can solve in 1 second

Solution :

For n , the time = sqrt(n) microsecond - ( i )

So, for 1 second time, the size will be given as

time = 1 second

= microseconds

time  = microseconds

Comparing with equation ( i ) , we get

n =

i.e n = 10^12

Answer 2 : The array arr = [8, 5, 3, 6, 10] after the second iteration (when j = 3) of the j loop will look like [3, 5, 8, 6, 10].

Explanation :

I am assuming index starts at 1 here.

The given array is [8, 5, 3, 6, 10].

As per algorithm ,

Step 1 : For j = 1 ,

Key = A[ j ] = 8

i = j - 1 = 1 - 1 = 0

Inner while loop does not run and ends at the start because i = 0 which is invalid.

A [ i + 1 ] = key      =        A [ 1 ] = 8

Step 2 : For j = 2 ,

Key = A[ j ] = 5

i = j - 1 = 2 - 1 = 1

For (First inner iteration) ,

Condition (i > 0 and A[ i ] > key ) = 1>0 and A[ 1 ] > 5 = true and 8 > 5 = true and true = true

Therefore, A[ 2 ] = 8 and i = i – 1 = 1 – 1 = 0

Then while loop ends since i = 0 ( Second inner iteration)

A [ i + 1 ] = key      =        A [ 2 ] = 8

  [5, 8, 3, 6, 10].

Step 3 : For j = 3 ,

Key = A[ j ] = 3

i = j - 1 = 3 - 1 = 2

For (First inner iteration )

Condition (i > 0 and A[ i ] > key )          = 2>0 and A[ 2 ] > 3 = true and 8 > 3 = true and true = true

Therefore, A[ 3 ] = A [ 2 ]       A [ 3 ] = 8 and i = i – 1 = 2 – 1 = 1

The array will be   [5, 8, 8, 6, 10].

For (Second inner iteration)

Condition (i > 0 and A[ i ] > key )              = 1>0 and A[ 1 ] > 3 = true and 5 > 3 = true and true = true

Therefore, A[ 2 ] = A [ 1 ]       A [ 2 ] = 5 and i = i – 1 = 1 – 1 = 0

The array will be   [5, 5, 8, 6, 10].

For (Third inner iteration)

While loop ends since i = 0 which is invalid.

A [ i + 1 ] = key      =        A [ 1 ] = 3

The array will be   [3, 5, 8, 6, 10].


Related Solutions

How much time does an algorithm take to solve a problem of size n if this...
How much time does an algorithm take to solve a problem of size n if this algorithm uses 2n2 + 2n operations, each requiring 10-8 seconds, with these values of n? a) 10: b) 20: c) 50: d) 100
In Java Find the second largest and second smallest element in a given array. You can...
In Java Find the second largest and second smallest element in a given array. You can hardcode/declare the array in your program.
Finding the complexity of Finding the largest two elements in a queue of size n+3 using...
Finding the complexity of Finding the largest two elements in a queue of size n+3 using Naïve search. with explain
Please explain how to do this problem and solve. Bid Ask Price Size Price Size $...
Please explain how to do this problem and solve. Bid Ask Price Size Price Size $ 94 150 $ 94.5 300 $ 93.5 300 $ 94.8 300 $ 92 600 $ 95 500 $ 90.8 450 $ 95.5 550 b. Norman Pilbarra submits a market order to buy 600 shares. What is the maximum price that he will pay? (Round your answer to 2 decimal places.)
Assuming the population has an approximate normal distribution, if a sample size n = 24 has...
Assuming the population has an approximate normal distribution, if a sample size n = 24 has a sample mean ¯ x = 49 with a sample standard deviation s = 2 , find the margin of error at a 99% confidence level. THEN YOU MUST ROUND TO TWO DECIMALS..
For each of these problems, please use first a mathematical formula to solve the problem. Second...
For each of these problems, please use first a mathematical formula to solve the problem. Second use Excel spreadsheet to also solve the problem. You are thinking about leasing a car. The purchase price of the car is $30,000. The residual value (the amount you could pay to keep the car at the end of the lease) is $15,000 at the end of 36 months. Assume the first lease payment is due one month after you get the car. The...
6 C++ Questions: 19. Assuming an int is size 4 bytes, what is the size in...
6 C++ Questions: 19. Assuming an int is size 4 bytes, what is the size in memory of the below array: int cards[10] = {7, 4, 7, 5, 7}; 20. In the array from question 19, what is the value of the below elements: cards[1]; cards[8]; Assume you have an array with 128 integers which is sorted from lowest to highest. 21a. You are searching for a value which is contained in the array using the binary search algorithm. What...
Assuming the population has an approximate normal distribution, if a sample size n=10 has a sample...
Assuming the population has an approximate normal distribution, if a sample size n=10 has a sample mean ¯x=36 with a sample standard deviation s=9, find the margin of error at a 90% confidence level. THEN YOU MUST ROUND ANSWER TO TWO DECIMALS PLACES.
can anyone solve this for me ? x(n) ={-2,-1,1,4,2} ( arrow at 1) y(n)={-4,2,-1,0,2} ( arrow...
can anyone solve this for me ? x(n) ={-2,-1,1,4,2} ( arrow at 1) y(n)={-4,2,-1,0,2} ( arrow at 0) I want the convolution and correlation of those two signals, first using tabular method and then graphically
**** LOOKING TO SOLVE THE SECOND PART TO THIS 2 PART QUESTION; PROBLEM 4 ONLY PLEASE...
**** LOOKING TO SOLVE THE SECOND PART TO THIS 2 PART QUESTION; PROBLEM 4 ONLY PLEASE **** Automobiles arrive at the drive-through window at a post office at the rate of 4 every 10 minutes. The average service time is 2 minutes. The Poisson distribution is appropriate for the arrival rate and service times are exponentially distributed. a) What is the average time a car is in the system? 10 minutes b) What is the average number of cars in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT