final-s05-sol-1

# final-s05-sol-1 - CS 70 Spring 2005 Discrete Mathematics...

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

CS 70 Discrete Mathematics for CS Spring 2005 Clancy/Wagner Final Solns Problem 1. (8 points) Let a ( n ) denote the number of ternary strings of length n with no pair of adjacent 2’s. Example: “2011” is a ternary string with no pair of adjacent 2’s. (a) What are a ( 1 ) and a ( 2 ) ? Solution: a ( 1 ) = 3, a ( 2 ) = 8. Grading: 1 pt for correct answer. Solution #1: a ( n ) = 2 a ( n - 1 ) + 2 a ( n - 2 ) for n 3. JustiFcation: If the Frst digit is 0 or 1 (2 choices), then the remaining n - 1 digits can be any ternary string with no 22s ( a ( n - 1 ) choices). If the Frst digit is 2 (1 choice), then the second digit can be 0 or 1 (2 choices), and the remaining n - 2 digits can be any ternary string with no 22s ( a ( n - 2 ) choices). Solution #2: a ( n ) = 3 a ( n - 1 ) - 2 a ( n - 3 ) for n 4. JustiFcation: Take any ternary string of length n - 1 with no 22s, and append 0, 1, or 2 (3 a ( n - 1 ) choices). We need to exclude strings of the form ··· 022 and ··· 122 (2 a ( n - 3 ) choices); once we’ve eliminated these, what remains must be exactly the set of ternary strings of length n with no 22s. Common mistakes: Overcounting. ±or example, some said a ( n ) = 3 n - 3 n - 2 ( n - 1 ) , reasoning that there are 3 n - 2 ( n - 1 ) ternary strings with a 22, since there are n - 1 places where the 22 could start and 3 n - 2 options for the other n - 2 digits in the string. The problem with this reasoning is that it overcounts strings with multiple 22s; for instance, the string 22022 is counted twice, and the string 22222 is counted four times. Grading: 3 pts for a correct recurrence; 1 pt for something with a partial explanation. (b) Prove that a ( n ) 2 n + 1 for all n 2. Solution #1: Proof by strong induction. Base cases: a ( 2 ) = 8 2 2 + 1 . a ( 3 ) = 22 2 3 + 1 . Induction step: Assume a ( k ) 2 k + 1 for k = 2 , 3 ,..., n . Then for n 3, a ( n + 1 ) = 2 a ( n ) + 2 a ( n - 1 ) (by part (b)) 2 · 2 n + 1 + 2 · 2 n - 1 + 1 (by the inductive hypothesis) 2 · 2 n + 1 = 2 ( n + 1 )+ 1 . CS 70, Spring 2005, Final Solns 1

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

View Full Document
Solution #2: For each ternary string of length n with no 22s, we can get two unique ternary strings of length n + 1 with no 22s by appending either a 0 or a 1. This shows that a ( n + 1 ) 2 a ( n ) for all n 1. Now use induction to show the desired result. Solution #3: There are 2 n ternary strings (of length n ) with no 2. There are n × 2 n - 1 more that have exactly one 2. Thus there are at least 2 n + n × 2 n - 1 ternary strings of length n with no 22. Moreover, 2 n + n × 2 n - 1 2 n + 2 × 2 n - 1 2 n + 1 for n 2. Grading: 4 pts for an impeccable proof. For induction proofs: 1 pt for all needed base cases and a correctly stated induction predicate; 3 pts for a correct and fully justi±ed inductive step. - 1 pt for backwards reason- ing, for steps with no justi±cation, for small algebraic errors, for confusing what you can assume vs. what you must prove, or for confusion between integers and booleans (e.g.,
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 10

final-s05-sol-1 - CS 70 Spring 2005 Discrete Mathematics...

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

View Full Document
Ask a homework question - tutors are online