# hw8-sol - CS 173: Discrete Structures, Spring 2010 Homework...

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

CS 173: Discrete Structures, Spring 2010 Homework 8 Solutions This homework contains 5 problems worth a total of 46 regular points. 1. Solving recurrences [10 points] (a) Use unrolling to Fnd a closed form for the following recurrence, for inputs that are powers of 2. Show at least three steps of unrolling, convert to a closed form, and simplify your closed form. p ( n ) = b 4 p ( n 2 ) if n > 1 2 otherwise [Solution:] p ( n ) = 4 p ( n 2 ) p ( n ) = 4(4 p ( n 4 )) p ( n ) = 4(4(4 p ( n 8 ))) p ( n ) = 4 3 · p ( n 2 3 ) p ( n ) = 4 4 · p ( n 2 4 ) · · · · ·· p ( n ) = 4 log 2 n · p ( n n ) p ( n ) = 4 log 2 n · 2 p ( n ) = (2 2 ) log 2 n · 2 p ( n ) = (2 log 2 n ) 2 · 2 p ( n ) = 2 n 2 (b) The function g : Z + Z + is deFned below. ±ind a closed form for g , correctly handling inputs that aren’t powers of three. Show your work and/or provide a brief explanation. However, it is not necessary to show details of unrolling, since it’s very similar to a problem you did for homework 7. g ( n ) = b g ( n 3 ) + 21 if n 3 0 otherwise [Solution:] The unrolling occurs in the same way as Problem 2(b) from HW7. Since as a property of ⌊⌋ , the form x y z = x y z . g ( n ) = g ( n 3 3 ) + 2 · 21 = g ( n 3 2 ) + 2 · 21 g ( n ) = g ( n 3 3 ) + 3 · 21 · · · · · · In this case g ( n ) = (log 3 n ) ⌋ ∗ 21 Another reasonable way to show work informally would be a table of input and output values near several of the places where the output value changes. 1

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

View Full Document
2. Recurrence tree [10 points] Consider the following recurrence: T ( n ) = d if n < = 4 T ( n ) = 2 T ( n/ 2) + cn + p otherwise where c , d , and p are constants. Let’s analyze T when the input n is a power of 2. (a) Draw a recursion tree for T , in which each node shows the contribution of the non- recursive term cn + p . [Solution:] (b) How many levels does this tree have (exact answer, not just big-O)? [Solution:]
This is the end of the preview. Sign up to access the rest of the document.

## hw8-sol - CS 173: Discrete Structures, Spring 2010 Homework...

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

View Full Document
Ask a homework question - tutors are online