Question

Pseudocode Algorithm Sub(n) if n = 1 or n = 2 return n - 1 else...

Pseudocode

Algorithm Sub(n)

if n = 1 or n = 2

return n - 1

else

return Sub(n - 1) + Sub(n - 1)

Let Sub(n) be the number of "substraction operation" as the basic operation on input of size n.

what is the recurrence for Sub(n).

please show working.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Recurrence for Sub(n:
T(n) = 2T(n-1) + 1

Basic case:
T(n) = 0

Solving recurrence is
T(n) = 2T(n-1) + 1
    = 2(2T(n-2)+1) + 1
    = 2^2T(n-2)+2 + 1
    = 2^3T(n-3)+ 2^2 +2 + 1
    .....
    .....
    = 2^nT(n-n)+ ... + 2^2 +2 + 1
    = 2^nT(0)+ ... + 2^2 +2 + 1
    = 2^n+ ... + 2^2 +2 + 1
    = 2^(n+1)
    = O(2^n)
Add a comment
Know the answer?
Add Answer to:
Pseudocode Algorithm Sub(n) if n = 1 or n = 2 return n - 1 else...
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