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...
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...
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
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...
(8%) Write a C/C++ program that takes an input (array) from 1 to n (say n...
(8%) Write a C/C++ program that takes an input (array) from 1 to n (say n = 50) and displays the string representations of those numbers with following conditions If the current number is divisible by 2, then print CSU If the current number is divisible by 5, then print SB If the current number is divisible by both 2 and 5, then print CSUSB If the number is neither divisible by 2 nor 5, then print the number Example:...
computer ,input and output device sof computer
What is computer list some input and output devices  of compueter.
Let An={2-n,2-2n,2-3n,…} where n∈N . Find A3∩A5 , A15∩A21 , A4∩A12 , Ak∩Akl , where k,l∈N...
Let An={2-n,2-2n,2-3n,…} where n∈N . Find A3∩A5 , A15∩A21 , A4∩A12 , Ak∩Akl , where k,l∈N . Prove also that A1∩A2∩A3∩A4∩…=∅ .
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT