A fast algorithm is most useful  you don't want the answer to your question in 10 years, do you? Runtime analysis studies how long an algorithm will take to complete, on average or in the worst case.
Prefix sums of a sequence of numbers \(a_0,a_1,a_2,a_3\ldots\) are given by a second sequence of numbers \(s_0,s_1,s_2,s_3\ldots\) defined as
\[s_j = \sum_{i=1}^{j}a_i \]
The Python code below computes prefix sums.
1 2 3 4 5 6 7 8 9 

Analyze the the code and find the lines that will be executed the greatest number of times. Input the sum of the line number of these lines as your answer.
Details and assumptions
The fragment of Java code below describes a recursive method \(P\) that takes two integer parameters \(x\) and \(n\) and returns an integer.
1 2 3 4 5 6 7 8 9 10 11 12 13 

Analysis shows us that the running time of this function for large \(n\) can be expressed as \[T(n) = O(g(n)) \] for some function \(g(n)\). What is the value of \(4^{g(1)}\)?
Details and assumptions
int
primitive type and assume the behavior of the method is not affected for large inputs.1 2 3 4 5 6 7 8 9 10 11 

Consider the above recursive algorithm above, where the random(int n)
spends one unit of time to return a random integer which is evenly distributed within the range \([0,n]\). If the average processing time is \(T(n)\), what is the value of \(T(6)\)?
Assume that all instructions other than the random cost a negligible amount of time.
The simple recursive python program below can be used to compute the \(n^{th}\) Fibonnaci number.
1 2 3 4 5 

It can be shown that a tight bound of this program is given by \[ T(n) = \Theta(g(n)) \] for some function \(g(n)\). What is the value of \(g(17)\)?
Details and assumptions
An obvious algorithm for exponentiation (\(x^{n}\)) takes \(n1\) multiplications. Suppose we propose a faster algorithm for the case where \(n=2^{m}\). The "BigO" complexity of such an algorithm can be expressed as:
\[T(n)=O(g(n))\]
what is the value of \(g(128)\)?
Problem Loading...
Note Loading...
Set Loading...