RecRelPractice-sol - Practice with Recurrence Relations...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Practice with Recurrence Relations (Solutions) Solve the following recurrence relations using the iteration technique: 1) ° ( ± ) = ° ( ± − 1) + 2 , ° (1) = 1 ================================================ T(n) = T(n-1) + 2 T(1) = 1 T(n) = T(n-1) + 2 = [T(n-2) + 2] + 2 = T(n-2) + 2 + 2 T(n) = T(n-2) + 2*2 T(n) = T(n-2) + 2*2 = [T(n-3) + 2] + 2*2 = T(n-3) + 2 + 2*2 T(n) = T(n-3) + 2*3 Substituting Equations n n -1 T(n-1) = T(n-2) + 2 T(n-2) = T(n-3) + 2 T(n-3) = T(n-4) + 2 T(n-4) = T(n-5) + 2 T(n) = T(n-3) + 2*3 = [T(n-4) + 2] + 2*3 = T(n-4) + 2 + 2*3 T(n) = T(n-4) + 2*4 Do it one more time… T(n) = T(n-4) + 2*4 So now rewrite these five equations and look for a pattern: T(n) = T(n-1) + 2*1 1 st step of recursion T(n) = T(n-2) + 2*2 2 nd step of recursion T(n) = T(n-3) + 2*3 3 rd step of recursion T(n) = T(n-4) + 2*4 4 th step of recursion T(n) = T(n-5) + 2*5 5 th step of recursion Generalized recurrence relation at the kth step of the recursion: T(n) = T(n-k) + 2*k We want T(1). So we let n-k = 1. Solving for k, we get k = n - 1. Now plug back in. T(n) = T(n-k) + 2*k T(n) = T(1) + 2*(n-1), and we know T(1) = 1 T(n) = 2*(n-1) = 2n-1 We are done. Right side does not have any T(…)’s. This recurrence relation is now solved in its closed form, and it runs in O(n) time.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2) ° ( ± ) = 2 ° ( ± /2) + ± , ° (1) = 1 ================================================ T(n) = 2T(n/2) + n
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

RecRelPractice-sol - Practice with Recurrence Relations...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online