practice-questions

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

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Consider the recurrence relation R ( n ) = { 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 =...
View Full Document

This note was uploaded on 07/28/2009 for the course CSE 21 taught by Professor Graham during the Spring '07 term at UCSD.

Page1 / 2

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

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online