Question

3. 0 marks Suppose you have an algorithm which has the following recurrence relation for W(n), assuming n is a power of 2, i.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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

Add a comment
Know the answer?
Add Answer to:
3. 0 marks Suppose you have an algorithm which has the following recurrence relation for W(n),...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT