Question

T(n) = T(n-2) + 1 for all n > 2. where T(1) = T(2) = 1....

T(n) = T(n-2) + 1 for all n > 2. where T(1) = T(2) = 1. Find the even case and odd case.

Recursion relation

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

Given that T(n) = T(n - 2) + 1

T(n) = (T(n - 4) + 1) + 1 (By putting T(n - 2) = T(n - 4) + 1 while assuming n-2 > 2)

T(n) = T(n - 4) + 2

Now put value of T(n - 4) = T(n - 6) + 1 in above equation assuming that n - 4 > 2

T(n) = T(n - 6) + 3

From this, we make a hypothesis that T(n) = T(n - 2*k) + k (where k is any integer)

To prove the above hypothesis, we apply mathematical induction on k

Base case : k = 1

Then above becomes T(n) = T(n - 2) + 1 (This is true by given recurrence in question)

Hypothesis step : we assume that T(n) = T(n - 2*k) + k is true for k.

Inductive step : We will prove it for k + 1 given that it is true for k

To prove : T(n) = T(n - 2*(k + 1)) + (k+1)

T(n) = T(n - 2*k - 2) + (k + 1)

T(n) = T((n - 2*k) - 2) + (k + 1) [Equation 1]

Now T(n - 2*k) = T((n - 2*k) - 2) + 1 [From recurrence relation given in question]

So putting this value in Equation 1, we get

T(n) = T(n - 2*k) + k

and we know that above equation is true from hypothesis step,

So our hypothesis is true that T(n) = T(n - 2*k) + k from some integer k

Now,

Odd case : n is odd

we know that n is odd and 2*k must be even (for any integer k), So n - 2*k is odd.

so we will find value of k for which n - 2*k = 1

k = (n - 1)/2 (Note that n is odd so n - 1 is even there (n - 1)/2 must be integer)

now put value of k = (n - 1)/2 in equation T(n) = T(n - 2*k) + k

T(n) = T(n - 2*(n - 1)/2) + (n - 1)/2

T(n) = T(n - (n - 1)) + (n - 1)/2

T(n) = T(1) +  (n - 1)/2

T(n) = 1 + (n - 1)/2 (Given T(1) = 1)

T(n) = (n + 1)/2  where n is odd

Even Case : n is even

We know

T(n) = T(n - 2*k) + k from some integer k

n is even and 2*k must also be even (for any integer k), So n - 2*k must also be even

We will find value of k for which n - 2*k = 2

k = (n - 2)/2

put value of k in equation T(n) = T(n - 2*k) + k

T(n) = T(n - 2*(n - 2)/2) + (n - 2)/2

T(n) = T(n - (n - 2)) + (n - 2)/2

T(n) = T(2) + (n - 2)/2

T(n) = 1 + (n - 2)/2 (T(2) = 1)

T(n) = n/2  where n is even

--------------------------------------------------------------------------------------------------

PS : If you have any doubt regarding this solution please comment and if you like this solution then please upvote.

Thanks

Add a comment
Know the answer?
Add Answer to:
T(n) = T(n-2) + 1 for all n > 2. where T(1) = T(2) = 1....
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