Recursion and Induction: A Comprehensive Guide with Examples and Proofs, Exams of Calculus

Use induction to prove that the recursive algorithm solves the Tower of Hanoi problem. Calculate M(n) for small n and look for a pattern. Guess the result and ...

Typology: Exams

2022/2023

Uploaded on 03/01/2023

ehimay
ehimay 🇺🇸

4.8

(20)

268 documents

1 / 49

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31

Partial preview of the text

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