hw8-sol - CS 173: Discrete Structures, Fall 2010 Homework 8...

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

View Full Document Right Arrow Icon
CS 173: Discrete Structures, Fall 2010 Homework 8 Solutions This homework contains 3 problems worth a total of 37 regular points and one bonus point. 1. More on recurrences [12 points] (a) (6 points) Derive closed form solutions for the following two recurrences. i. T (0) = 2 and T ( n ) = ( n + 1) T ( n - 1) . [Solution:] We will solve this problem using unrolling. T ( n ) = ( n + 1) T ( n - 1) = ( n + 1) · n · T ( n - 2) = ( n + 1) · n · ( n - 1) · T ( n - 3) = ..... = ( n + 1) · n · ( n - 1) · ( n - 2) ... ( n - k ) · T ( n - ( k + 2)) In order to reach the base case we need n - ( k + 2) = 0. So k = n - 2 and we get follwing. T ( n ) = ( n + 1) · n · ( n - 1) ... · n - ( n - 2) · T (0) = ( n + 1) · n · ( n - 1) ... · 2 · 2 = 2 · ( n + 1)! ii. T (0) = 1 and T ( n ) = T ( n - 1) + 3( n - 1) 2 + 3( n - 1) + 1 . [Solution:] T ( n ) = T ( n - 1) + 3( n - 1) 2 + 3( n - 1) + 1 = T ( n - 2) + 3( n - 2) 2 + 3( n - 1) 2 + 3( n - 2) + 3( n - 1) + 2 = T ( n - 3) + 3( n - 3) 2 + 3( n - 2) 2 + 3( n - 1) 2 +3( n - 3) + 3( n - 2) + 3( n - 1) + 3 = ... = T ( n - k ) · 3( n - k ) 2 + ... + 3( n - 1) 2 + 3( n - k ) + ... + 3( n - 1) + k In order to reach the base case n - k = 0 . So n = k and we get following. 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
T ( n ) = T (0) + 3(0 2 + 1 2 + ... + ( n - 1) 2 ) + 3(0 + 1 + 2 + ... + ( n - 1)) + n = 1 + 3( n - 1 X i =1 i 2 ) + 3( n - 1 X i =1 i ) + 3 n - 2 n = 1 + 3( n - 1 X i =1 i 2 ) + 3( n X i =1 i ) - 2 n = 1 + 3( ( n - 1)( n )(2 n - 1) 6 ) + 3( n ( n + 1) 2 ) - 2 n = 1 + 3 · n ( ( n - 1)(2 n - 1) 6 + n + 1 2 ) - 2 n = 1 + 3 · n ( ( n - 1)(2 n - 1) + 3( n + 1) 6 ) - 2 n = 1 + 3 · n ( 2 n 2 + 4 6 ) - 2 n = 1 + n ( n 2 + 2) - 2 n = 1 + n 3 + 2 n - 2 n = 1 + n 3 (b) (6 points) Give closed form of the following recurrence using recursion tree. i. T (1) = 1 and T ( n ) = 4 T ( n/ 2) + n 3 Assume n is power of 2. [Solution:] The recursion tree is shown in Figure 1. The height of the tree is log 2 n . At each level i there are 4 i nodes and total work done at each level is 4 i ( n 2 i ) 3 . T ( n ) = log 2 n X i =0 4 i ( n 2 i ) 3 = n 3 · log 2 n X i =0 ( 4 i 2 3 i ) = n 3 · log 2 n X i =0 ( 4 8 ) i = n 3 · log 2 n X i =0 ( 1 2 ) i = n 3 ( (1 / 2) log 2 n +1 - 1 (1 / 2) - 1 ) = 2 n 3 (1 - (1 / 2) log 2 n +1 ) = n 3 (2 - (1 / 2) log 2 n ) = 2 n 3 - n 3 (1 /n ) = 2 n 3 - n 2 2
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 / 8

hw8-sol - CS 173: Discrete Structures, Fall 2010 Homework 8...

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