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.
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...
For the following program segments, write a program that shows the estimated runtime for each piece....
For the following program segments, write a program that shows the estimated runtime for each piece. Run it on your computer when n=1, 10, 100, 1000, 10000, 100000, 1000000 for ten times each so that you can observe the differences in performance among these segments. Segment1:        for (sum=0, i=1; i<=n; i++)                         sum = sum + i; Segment2:        for (sum=0, i=1; i<=n; i++)                                                 for (j=1; j<=i; j++)                                                             sum++; Segment3:        sum= n * (n+1)/2
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
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
Write a program to do the following. • Input an integer n. • Create a BST...
Write a program to do the following. • Input an integer n. • Create a BST S inserting the keys 1, 2, . . . , n in that order, which will result in a completely-skewed tree. • Measure the time to search for n + 1 in S. • Display the time taken for search. /** * Exception class for access in empty containers * such as stacks, queues, and priority queues. * @author Mark Allen Weiss */ public...
Write a program to do the following. • Input an integer n. • Create a BST...
Write a program to do the following. • Input an integer n. • Create a BST B containing the same items, but inserting them in an order that will yield the tree balanced. The following algorithm, known as pre-order traversal, gives you a strategy to produce that sequence. seq(low, high, T){    if (low <= high){        mid = (low+high)/2        T.insert(mid)        seq(low, mid-1, T)        seq(mid+1, high, T)    } } • Measure the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT