Recursive Sequences Lecture 24 Section 5.6 Robb T. Koether Hampden-Sydney College Wed, Feb 26, 2014 Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 1 / 26
1 Recursive Sequences The Fibonacci Sequence Choosing Subsets The Catalan Numbers The Towers of Hanoi 2 Assignment Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 2 / 26
Outline 1 Recursive Sequences The Fibonacci Sequence Choosing Subsets The Catalan Numbers The Towers of Hanoi 2 Assignment Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 3 / 26
Recursive Sequences Definition (Recursive Sequence) A sequence a 0, a 1, a 2,... is recursive if, for all i k for some integer k > 0, each term a i is defined in terms of certain terms a j with j < i. The initial conditions specify the values of a 0, a 1,..., a k 1. In most examples, we specify the first one or two terms and then define all subsequent terms in terms of the previous one or two terms. Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 4 / 26
Outline 1 Recursive Sequences The Fibonacci Sequence Choosing Subsets The Catalan Numbers The Towers of Hanoi 2 Assignment Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 5 / 26
The Fibonacci Sequence The Fibonacci sequence is a well known example. Define F 0 = 0 and F 1 = 1. Define recursively F n = F n 1 + F n 2 for all n 2. The first few terms are 0, 1, 1, 2, 3, 5, 8, 13, 21, 34. Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 6 / 26
Outline 1 Recursive Sequences The Fibonacci Sequence Choosing Subsets The Catalan Numbers The Towers of Hanoi 2 Assignment Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 7 / 26
Choosing Subsets In how many ways can 2 elements be selected from a set of n elements? Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 8 / 26
Choosing Subsets In how many ways can 2 elements be selected from a set of n elements? Let a n be the number of such ways, for n 2. Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 8 / 26
Choosing Subsets In how many ways can 2 elements be selected from a set of n elements? Let a n be the number of such ways, for n 2. Clearly, a 2 = 1. Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 8 / 26
Choosing Subsets In how many ways can 2 elements be selected from a set of n elements? Let a n be the number of such ways, for n 2. Clearly, a 2 = 1. It is easy to see that a 3 = 3. Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 8 / 26
Choosing Subsets n elements Consider a set of n elements Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 9 / 26
Choosing Subsets n - 1 elements Remove one element Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 9 / 26
Choosing Subsets n - 1 elements There are a n 1 ways to choose 2 elements not using the removed element Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 9 / 26
Choosing Subsets n - 1 elements There are n 1 ways to choose 2 elements using the removed element Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 9 / 26
Choosing Subsets Thus, a n = a n 1 + (n 1). Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 10 / 26
Choosing Subsets Thus, a n = a n 1 + (n 1). It follows that a n = 1 + 2 + 3 + + (n 1) = (n 1)n. 2 Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 10 / 26
Choosing Subsets In how many ways can 3 elements be selected from a set of n elements? Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 11 / 26
Choosing Subsets In how many ways can 3 elements be selected from a set of n elements? Let b n be the number of such ways, for n 3. Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 11 / 26
Choosing Subsets In how many ways can 3 elements be selected from a set of n elements? Let b n be the number of such ways, for n 3. Clearly, b 3 = 1. Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 11 / 26
Choosing Subsets In how many ways can 3 elements be selected from a set of n elements? Let b n be the number of such ways, for n 3. Clearly, b 3 = 1. How is b n related to b n 1? Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 11 / 26
Outline 1 Recursive Sequences The Fibonacci Sequence Choosing Subsets The Catalan Numbers The Towers of Hanoi 2 Assignment Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 12 / 26
Binary Trees How many distinct binary trees are there with exactly n vertices? Let a n be the number of distinct binary trees with exactly n vertices. Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 13 / 26
Binary Trees Binary trees with 1 vertex a 1 = 1 Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 14 / 26
Binary Trees Binary trees with 2 vertices a 2 = 2 Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 14 / 26
Binary Trees Binary trees with 3 vertices a 3 = 5 Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 14 / 26
Binary Trees Binary trees with 4 vertices a 4 = 14 Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 14 / 26
The Catalan Numbers The Catalan numbers can be defined recursively as C 0 = 1 and C n = C 0 C n 1 + C 1 C n 2 + + C n 1 C 0, for all n 1. The first few terms are 1, 1, 2, 5, 14, 42, 132. Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 15 / 26
The Catalan Numbers ( ) They can also be defined recursively C n = 2 2n 1 n+1 C n 1 for all n 1. They can also be defined nonrecursively as C n = 1 ( ) 2n. n + 1 n Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 16 / 26
Routes Through a Graph B A How many paths are there from A to B, moving north and east? Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 17 / 26
Routes Through a Graph B A Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 17 / 26
Routes Through a Graph B A Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 17 / 26
Routes Through a Graph B A Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 17 / 26
Routes Through a Graph B A Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 17 / 26
Routes Through a Graph B A Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 17 / 26
Routes Through a Graph B A Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 17 / 26
Routes Through a Graph B A Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 17 / 26
Routes Through a Graph B A Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 17 / 26
Routes Through a Graph B A Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 17 / 26
Routes Through a Graph B A Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 17 / 26
Routes Through a Graph B A Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 17 / 26
Routes Through a Graph B A Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 17 / 26
Routes Through a Graph B A Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 17 / 26
Routes Through a Graph B A Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 17 / 26
Outline 1 Recursive Sequences The Fibonacci Sequence Choosing Subsets The Catalan Numbers The Towers of Hanoi 2 Assignment Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 18 / 26
The Towers of Hanoi The Towers of Hanoi puzzle has three pegs (Peg 1, Peg 2, Peg 3) with n disks stacked on Peg 1. A legal move is to move a single disk to another peg without placing a larger disk on a smaller disk. The goal is to assemble all n disks on Peg 3. How many moves will it take? Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 19 / 26
The Towers of Hanoi Peg 1 Peg 2 Peg 3 All 8 disks on Peg 1 Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 20 / 26
The Towers of Hanoi Peg 1 Peg 2 Peg 3 Reassemble 7 disks on Peg 2 Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 20 / 26
The Towers of Hanoi Peg 1 Peg 2 Peg 3 Move largest disk to Peg 3 Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 20 / 26
The Towers of Hanoi Peg 1 Peg 2 Peg 3 Reassemble 7 disks on Peg 3 Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 20 / 26
The Towers of Hanoi We see that we can solve the puzzle for 8 disks if we can solve it for 7 disks. So we can solve it for 7 disks if we can solve it for 6 disks. And so on, down to 2 disks: we can solve it for 2 disks if we can solve it for 1 disk. How do we solve it for 1 disk? Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 21 / 26
The Towers of Hanoi Peg 1 Peg 2 Peg 3 The solution for 8 disks using the solution for 6 disks Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 22 / 26
The Towers of Hanoi Peg 1 Peg 2 Peg 3 Reassemble 6 disks on Peg 3 Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 22 / 26
The Towers of Hanoi Peg 1 Peg 2 Peg 3 Move Disk 7 to Peg 2 Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 22 / 26
The Towers of Hanoi Peg 1 Peg 2 Peg 3 Reassemble 6 disks on Peg 2 Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 22 / 26
The Towers of Hanoi Peg 1 Peg 2 Peg 3 Move Disk 8 to Peg 3 Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 22 / 26
The Towers of Hanoi Peg 1 Peg 2 Peg 3 Reassemble 6 disks on Peg 1 Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 22 / 26
The Towers of Hanoi Peg 1 Peg 2 Peg 3 Move Disk 7 to Peg 3 Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 22 / 26
The Towers of Hanoi Peg 1 Peg 2 Peg 3 Reassemble 6 disks on Peg 3 Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 22 / 26
The Towers of Hanoi How many moves are required to solve the puzzle for n disks? Let m n be the number of moves required when there are n disks. When n = 1: m 1 = 1. When n = 2: m 1 + 1 + m 1 = 3. When n = 3: m 2 + 1 + m 2 = 7. In general, m n = 2m n 1 + 1. Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 23 / 26
The Towers of Hanoi We can show by induction that m n = 2 n 1. Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 24 / 26
Outline 1 Recursive Sequences The Fibonacci Sequence Choosing Subsets The Catalan Numbers The Towers of Hanoi 2 Assignment Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 25 / 26
Assignment Assignment Read Section 5.6, pages 290-301. Exercises 2, 5, 11, 14, 22, 23, 27, 28, 33, page 302. Robb T. Koether (Hampden-Sydney College) Recursive Sequences Wed, Feb 26, 2014 26 / 26