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...
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...
computer ,input and output device sof computer
What is computer list some input and output devices  of compueter.
Write a short main program that reads an integer n from standard input and prints (to...
Write a short main program that reads an integer n from standard input and prints (to standard output) n lines of * characters. The number of *’s per line should double each time, starting with 1. E.g., if n = 5, the output should be as follows: * ** **** ******** ****************
Write a program called x.c that reads an integer n from standard input, and prints an...
Write a program called x.c that reads an integer n from standard input, and prints an nxn pattern of asterisks and dashes in the shape of an "X". You can assume n is odd and >= 5. Solve this problem using only while loop. Solution: ./x Enter size: 5 *---* -*-*- --*-- -*-*- *---* ./x Enter size: 9 *-------* -*-----*- --*---*-- ---*-*--- ----*---- ---*-*--- --*---*-- -*-----*- *-------* ./x Enter size: 15 *-------------* -*-----------*- --*---------*-- ---*-------*--- ----*-----*---- -----*---*----- ------*-*------ -------*------- ------*-*------...
Write a program to implement problem statement below: provide the menu for input N and number...
Write a program to implement problem statement below: provide the menu for input N and number of experiment M to calculate average time on M runs. randomly generated list. State your estimate on the BigO number of your algorithm/program logic. (we discussed in the class) Measure the performance of your program by given different N with randomly generated list with multiple experiment of Ns against time to draw the BigO graph (using excel) we discussed during the lecture. Lab-08-BigBiggerBiggtest.png ***...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT