{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

practice-questions

# practice-questions - Consider the recurrence relation 0 R(n...

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

Consider the recurrence relation R ( n ) = { 0 if n = 0 R ( n -1) + 2 n - 2 if n > 0 Which of the following formulae is a solution to R ( n )? 2 n - 2 n 2 - 2 n 2 - n n 2 - 2 n 2 n 2 - 2 n Proof. R (0) = 0 = (0 2 - 0). For n > 0, suppose (as an inductive hypothesis) R ( n -1) = ( n -1) 2 - ( n -1). Then R ( n ) = R ( n -1) + 2 n - 2 by definition = ( n -1) 2 - ( n -1) + 2 n - 2 by i.h. = n 2 - 2 n + 1 - n + 1 + 2 n - 2 some algebra = n 2 + (2 n - 2 n ) - n + (2 - 2) rearranging terms = n 2 - n eliminating zero terms Q.E.D. recursion,recurrence relation,closed form solution,induction Let s be a binary string, and define a function C ( s ) recursively as: B. If s = λ, then C ( s ) = 0. R1. If s = s' 0 for some binary string s' , then C ( s ) = C ( s' ) + 1. R2. If s = s' 1 for some binary string s' , then C ( s ) = C ( s' ). What is the value of C (00110)? 2 3 5 6 7 We evaluate C (00110) from the top down: C (00110) = C (0011) + 1 by part R1 = C (001) + 1 by part R2 = C (00) + 1 by part R2 = C (0) + 1 + 1 by part R1

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

View Full Document
= C (λ) + 1 + 1 + 1 by part R1 = 0 + 1 + 1 + 1 = 3 by part B C ( s ) counts the occurrences of 0 in s . recursion,recursive definition,recursive function How many different ways are there to rearrange the letters in the word teeterer ?
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 2

practice-questions - Consider the recurrence relation 0 R(n...

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

View Full Document
Ask a homework question - tutors are online