Download Recursion and Induction: A Comprehensive Guide with Examples and Proofs and more Exams Calculus in PDF only on Docsity!
Recursion and Induction
- Themes
- Recursion
- Recurrence Definitions
- Recursive Relations
- Induction (prove properties of recursive programs and objects defined recursively)
- Examples
- Tower of Hanoi
- Gray Codes
- Hypercube
Recursion & Recurrence Relations
- Very handy for defining functions and data
types simply:
- Consider the nth Fibonacci number, F (^) n :
- = 1, if n = 0 or n=
- = Fn-1 + Fn-2 , for all n>
- Very handy when a large problem can be
broken in similar (but smaller) problems
- We’ll look at the Towers of Hanoi in a moment
Induction & Recursion
- Very similar notions. They have exactly the
same roots
- Inductive proofs apply in a very natural way
to recursive algorithms, and recurrence
relations
- This chapter will present tools we’ll use for
the rest of the course
- Also gives us the flavor of how we’ll
approach the rest of the material
Tower of Hanoi
- There are three towers
- 64 gold disks, with decreasing sizes, placed on the first tower
- You need to move the stack of disks from one tower to another, one disk at a time
- Larger disks can not be placed on top of smaller disks
- The third tower can be used to temporarily hold disks
Recursive Solution
Recursive Solution
Recursive Solution
Tower of Hanoi
Tower of Hanoi
Tower of Hanoi
Tower of Hanoi
Tower of Hanoi
Recursive Algorithm
(defun move (from to)
(list (concatenate 'string from to)))
(defun hanoi (n from to using)
(if (equal n 1) (move from to) (append (hanoi (- n 1) from using to) (move from to) (hanoi (- n 1) using to from))))
Induction
- To prove a statement S(n) for positive integers n
- Need a base case (typically n=0 or n=1). Prove that S(0) or S(1) is true
- Assume S(n) is true [inductive hypothesis]
- Prove that S(n+1) is true. You’ll need to use the hypothesis in this step, or you did something wrong