W(n) = 2W(n/2) + 2n + 2 for n>1
W(n) = 1 for n=1 (Base Case)
Back substitution:
W(n) = 2W(n/2) + 2n + 2
or,
W(n) = 2*[2W(n/22) + 2n/2 + 2] + 2n + 2
or,
W(n) = 22W(n/22) + 2n + 22+ 2n + 2
or,
W(n) = 22W(n/22) + 2*(2n) + 22 + 2
or,
W(n) = 22[2W(n/23) +n/2+ 2] + 2*(2n) + 22 + 2
or,
W(n) = 23W(n/23) +2n+ 23+ 2*(2n) + 22 + 2
or,
W(n) = 23W(n/23) + 3*(2n)+ 23 + 22 + 2
or,
W(n) = 2kW(n/2k) + k*(2n)+ 2k + 2k-1+ ...................+ 23 + 22 + 2
Let n/2k = 1
Therefore n = 2k
or,
k = logn (base 2)
Now substituting k in the equation we get:-
W(n) = n*W(1) + logn*(2n)+ 2logn + 2logn-1+ ...................+ 23 + 22 + 2
From the base case W(1)=1
Substituting W(1) in the equation we get:-
W(n) = n + 2nlogn+ 2logn + 2logn-1+ ...................+ 23 + 22 + 2
Now 2+22+23+.............+2logn is a geometric series with number of terms x=logn, first term as a=2 and common divisor as r=2.
Sum of geometric series is given by a*(rx - 1)/(r-1)
or, 2*(2logn - 1)/(2-1)
or, 2*(n-1)
Substituting this sum in the previous equation we get W(n) as :-
W(n) = n + 2nlogn + 2n - 2
or,
W(n) = 2nlogn + 3n - 2
3. 0 marks Suppose you have an algorithm which has the following recurrence relation for W(n),...
3) [16 points total] Consider the following algorithm int SillyCalc (int n) int i; int Num, answer; if (n <= 4) return n 10; else { Num-SillyCalcl n/4) answer = Num + Num + 10; for (i-2; i<-n-1; ++) answer- answer+ answer; return answer; Do a worst case analysis of this algorithm, counting additions only (but not loop counter additions) as the basic operation counted, and assuming that n is a power of 2, i.e. that n- 2* for some...
For each of the following problems write a recurrence relation describing the running time of each of the following algorithms and determine the asymptotic complexity of the function defined by the recurrence relation. Justify your solution using substitution and carefully computing lower and upper bounds for the sums. Simplify and express your answer as Θ(n k ) or Θ(n k (log n)) wherever possible. If the algorithm takes exponential time, then just give exponential lower bounds. 5. func5 (A,n) /*...
Need answers for 1-5 Consider the following recurrence relation: H(n) = {0 if n lessthanorequalto 0 1 if n = 1 or n = 2 H(n - 1) + H (n - 2)-H(n - 3) if n > 2. (a) Compute H(n) for n = 1, 2, ...., 10. (b) Using the pattern from part (a), guess what H(100) is. 2. Consider the recurrence relation defined in Example 3.3 (FROM TEXT BOOK, also discussed in class and shown in slides)...
Solve the recurrence relation using iterative method subject to the basis step [13 points] s(1)=1 s(n)=s(n-1)+(2n-1),for n≥2 Then, verify the solution by using mathematical induction [7 points]
3. Determine the asymptotic complexity of the function defined by the recurrence relation. Justify your solution using expansion/substitution and upper and/or lower bounds, when necessary. You may not use the Master Theorem as justification of your answer. Simplify and express your answer as O(n*) or O(nk log2 n) whenever possible. If the algorithm is exponential just give exponential lower bounds c) T(n) T(n-4) cn, T(0) c' d) T(n) 3T(n/3) c, T() c' e) T(n) T(n-1)T(n-4)clog2n, T(0) c' 3. Determine the...
ALGORITHM RecS(n) // Input: A nonnegative integer n ifn=0 return 0 else return RecS(n+ n n n Determine what this algorithm computes. You must justify your answer. made by this algorithm and solve it. You must justify your answer. same thing using for/while loop(s) developed in (3). You must justify your answer. 1) 2) Set up the initial condition and recurrence relation for the number of multiplications 3) Write the pseudocode for the non-recursive version of this algorithm, i.e., compute...
*algorithm analysis and design* Solve the following recurrence relation T(n) = Tỉn/2) + 1 Using: 1-Recurrence Tree. 2-Master Therom.
(1) (1) (a) (14 pts.) Solve the following recurrence relation with the method of the charac- teristic equation: T(n) = 4T(n/2) + (n/2), for n > 1, n a power of 2 T(1) = 1 Determine the coefficients. (b) (1 PT.) What is the big O) order of the solution as a function of n? (c) (5 PTS.) Verify your solution by substituting back in the recurrence relation. (ii) (10 PTS.) Solve using the method of the characteristic equation to...
Algorithm Question: Problem 3. Solve the recurrence relation T(n) = 2T(n/2) + lg n, T(1) 0.
Given the sequence defined with the recurrence relation:$$ \begin{array}{l} a_{0}=2 \\ a_{k}=4 a_{k-1}+5 \text { for } n \geq 0 \end{array} $$A. (3 marks) Terms of Sequence Calculate \(a_{1}, a_{2}, a_{3}\) Keep your intermediate answers as you will need them in the next questionsB. ( 7 marks) Iteration Using iteration, solve the recurrence relation when \(n \geq 0\) (i.e. find an analytic formula for \(a_{n}\) ). Simplify your answer as much as possible, showing your work. In particular, your final...