Question

In: Computer Science

Suppose the runtime of a computer program is proportional to 2^n where n is the input...

  1. Suppose the runtime of a computer program is proportional to 2^n where n is the input size.

When given an input of size 1024, suppose the runtime is 256ms. For what input size would the program have runtime of 1ms?

  1. A program takes time proportional to the input size. If the program takes 36 milliseconds for input size 30, how  many milliseconds does it take for input size 10?
  1. A program takes time T(n) = k2n  where k is some constant and n is the input size. The program is run twice on the same computer (so k is the same in both cases). The first run is with n = 4 and the time taken is 20 ms. The second run is with n = 10. What is the time taken for the second run, in milliseconds? (Type in just the number; don't type "ms" at the end.)
  1. It's known that mergesort takes time proporitional to nlogn, where n is the array size. Now, on a given computer suppose mergesort takes 4 seconds to sort an array of size 1,000,000, how many milliseconds would you expect it to take to sort an array of size 1,000? Type in just the number; don't type "ms" at the end.
  1. A program takes time proportional to the square root of the input size. If the program takes 100 ms for input size 500, how many milliseconds does it take for input size 2,000?

Solutions

Expert Solution

1) since run time(t) is proportional to 2^n where n is the input size.

(where c is a constant)

when n=1024 , t=256ms

when run time t=1ms then the input size is

2) since time(t) is proportional to n where n is the input size.

(c is constant)

when n=30 t=36 ms

when n=10 then

3) Same method as above

when n=4, T=20ms

when n=10

4) Time complexity of merge sort =

So time(t) where c is constant

when n=1,000,000 t=4 seconds

4=k*1,000,000 * log (1,000,000)

k*log(1000^2)=4/1,000,000

2*k*log(1000)=4/1,000,000

k*log(1000)=2/(1000^2)

k*1000*log(1000)=2/1000 seconds=(2/1000)*1000 ms= 2ms

(if u want u can find the value of k and follow the long way, I noticed that 1000^2=1,000,000 so that can be used as a shortcut to solve it)

5)

         (c is constant)

when n=500 , t=100

when n=2000

t=100*2=200ms


Related Solutions

The runtime of a program is proportional to n1.5 where n is the input size.  For input...
The runtime of a program is proportional to n1.5 where n is the input size.  For input size 100 the runtime is 51 ms.  What is the new runtime when the input size is quadrupled?
Write a program (O(n), where n is the number of words) that takes as input a...
Write a program (O(n), where n is the number of words) that takes as input a set of words and returns groups of anagrams for those words. Complete your code here Do not change anything in the test file. CPP File: #include #include #include #include using namespace std; vector> findAnagrams(const vector& dict); vector> findAnagrams(const vector& dict) { // Your code here... } Test File: #include #include #include #include using namespace std; vector> findAnagrams(const vector& dict); int main() { vector word_list...
Find the runtime of this function, where n is an integer. int function(int n) { int...
Find the runtime of this function, where n is an integer. int function(int n) { int a = 0; for (int i = n; i > 0; i--) { for (int j = 0; j < i; j++) { a = a + i + j; } } return a; } Find the runtime of this function, where m and n are two integers. int f(int m, int n) { if (m==1 || n==1) { return 1; } return f(m,...
Suppose A^2= A , where A is an n by n matrix. Use Jordan canonical form...
Suppose A^2= A , where A is an n by n matrix. Use Jordan canonical form to thaw that A is diagonalizable.
Suppose an algorithm A1 has a runtime T1(n) defined ( in seconds) by the following function...
Suppose an algorithm A1 has a runtime T1(n) defined ( in seconds) by the following function T1(n) = n3 + 20n + 15 For n = 13, the runtime of the algorithm is 2472 seconds. Let us assume that we have an algorithm A2 with runtime given by T2(n) = n2 + 22n + 14? What will be the lowest value of n for which the runtime of A2 exceeds 2472 seconds? **Urgently needed**
In a language of your own choosing, write a computer program that takes as input a...
In a language of your own choosing, write a computer program that takes as input a decimal (base 10) floating point number, and converts this number into a binary floating-point representation. The binary floating-point representation should consist of 1 bit for the sign of the significand; 8 bits for the biased exponent; and 23 bits for the significand. In addition to program source code, provide a screenshot showing the tasks identified below. Provide an output that shows your input decimal...
Consider the following program specification: Input: An integer n > 0 and an array A[0..(n –...
Consider the following program specification: Input: An integer n > 0 and an array A[0..(n – 1)] of n integers. Output: The largest index b such that A[b] is the largest value in A[0..(n – 1)]. For example, if n = 10 and A = [ 4, 8, 1, 3, 8, 5, 4, 7, 1, 2 ] (so A[0] = 4, A[1] = 8, etc.), then the program would return 4, since the largest value in A is 8 and...
Foundation of Computer Science Describe an algorithm that takes as input a list of n integers...
Foundation of Computer Science Describe an algorithm that takes as input a list of n integers and produces as output the largest difference obtained by subtracting an integer in the list from the one following it. Write its corresponding program using your favorite programming language
1. Give the O-runtime depending on n for the code snippet below (n > 0). for(...
1. Give the O-runtime depending on n for the code snippet below (n > 0). for( j = n; j <= 0; j = j - 1)                                     for( k = 1; k <= n; k = k + 1)                                                 print(" "); 2. Give the O-runtime depending on n for the code snippet below (n > 0).            for( j = 1; j <= n; j = j + 1)                                     for( k = 1; k <= n; k =...
a) write a program to compute and print n, n(f), f(f(n)), f(f(f(n))).........for 1<=n<=100, where f(n)=n/2 if...
a) write a program to compute and print n, n(f), f(f(n)), f(f(f(n))).........for 1<=n<=100, where f(n)=n/2 if n is even and f(n)=3n+1 if n is odd b) make a conjecture based on part a. use java
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT