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

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

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

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

View Full Document
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
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 11/08/2010 for the course CS 173 taught by Professor [email protected]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */ during the Spring '08 term at University of Illinois at Urbana–Champaign.

• Spring '08
• [email protected]

### 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
Ask a homework question - tutors are online