lecture26

lecture26 - Lecture 26 Recursion, Counting Recap Induction...

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

Lecture 26 Recursion, Counting

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

View Full Document
Recap Induction Strong Induction Recursive structures, and structural induction
Complete Binary Trees Basis: a single vertex is a complete binary tree Recursive step: if T 1 and T 2 are complete binary trees, then the tree T 1 T 2 obtained by connecting a root r to the roots of T 1 and T 2 is also a complete binary tree r

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

View Full Document
Prove or Disprove A tree with n vertices has n-1 edges
Recursive Algorithms An algorithm is called recursive if it solves a problem by reducing it to a smaller instance of the same problem.

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

View Full Document
Computing n! Procedure factorial(n) If n=0, return 1 Else return n* factorial(n-1)
Computing GCD gcd(a,b) /* assumption a < b */ If a=0, then return b Else return gcd(b mod a, a)

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

View Full Document
Proving Correctness Correctness of recursive algorithms can be usually proven by induction. To prove that factorial(n) is correct: Induction on n Basis n = 0 ; factorial(0) returns 1, the correct answer. Inductive step: Suppose factorial(k) returns the correct answer: factorial(k+1) = (k+1)*factorial(k) = (k+1)*k! By the Ind. Hyp = (k+1)!
Fibonnaci(n) If n = 0, return 0 Else If n = 1, return 1 Else return Fibonacci(n-1) + Fibonacci(n-2)

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

lecture26 - Lecture 26 Recursion, Counting Recap Induction...

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

View Full Document
Ask a homework question - tutors are online