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

We can find and sort the k largest elements of a set of size n in...
We can find and sort the k largest elements of a set of size n in Θ(n + k log k) worst-case time. Is this statement true?
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.
Solve the following recurrences by assuming T(n) is constant for sufficiently small values of n and...
Solve the following recurrences by assuming T(n) is constant for sufficiently small values of n and find time complexity ?(?) = ?(? − 1) + ? (?/2) + ? ?(?) = 4? (?/3) + ???(?) ?(?)=?(?−2)+ 1/ lg(?)
What is the complexity of the given code as a function of the problem size n?  Show...
What is the complexity of the given code as a function of the problem size n?  Show all of the details of your analysis. for (int i = 0; i < 2*n; i++) {    if (i == n)    {       for (int j = 0; j < i; j++)          for (int k = 0; k < i; k++)             O(1)    }    else    {       for (int j = 0; j < i; j++)          O(1)    } }
Question 1: The word size of a computer generally indicates the largest integer it can process...
Question 1: The word size of a computer generally indicates the largest integer it can process in a single instruction. Discuss two different word sizes of computer systems and provide a brief comparison of both word size systems.(Discuss in one full page) Question 2: A computer has RAM of size 64 M words, its instruction set has 32 instructions and 16 registers in the CPU. What is the format and size of each of the following instructions? ADD R1,R2,R3 Move...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT