RecRelPractice-sol

# RecRelPractice-sol - Practice with Recurrence...

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

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.

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

View Full Document
2) ° ( ± ) = 2 ° ( ± /2) + ± , ° (1) = 1 ================================================ T(n) = 2T(n/2) + n
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 09/21/2011 for the course PHY 1500 taught by Professor Staff during the Spring '09 term at University of Central Florida.

### Page1 / 4

RecRelPractice-sol - Practice with Recurrence...

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

View Full Document
Ask a homework question - tutors are online