1 / 63

Recursively Defined Sequences

Recursively Defined Sequences. Lecture 40 Section 8.1 Wed, Apr 11, 2007. Recursive Sequences. A recurrence relation for a sequence { a n } is an equation that defines each term of the sequence as a function of previous terms, from some point on.

arvin
Download Presentation

Recursively Defined Sequences

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Recursively Defined Sequences Lecture 40 Section 8.1 Wed, Apr 11, 2007

  2. Recursive Sequences • A recurrence relation for a sequence {an} is an equation that defines each term of the sequence as a function of previous terms, from some point on. • The initial conditions are equations that specify the values of the first several terms a0, …, an – 1.

  3. Recursive Sequence • Define a sequence {ak} by • a0 = 2, • a1 = 3, • ak = ak – 1 + 2ak – 2, for all k 2. • The next few terms are • a2 = 7, • a3 = 13, • a4 = 27.

  4. The Towers of Hanoi • The Towers of Hanoi puzzle has • A game board , • Three pegs (Peg 1, Peg 2, Peg 3), • 10 disks, of 10 different sizes. • Initially, the 10 disks are stacked on Peg 1, each disk smaller than the disk below it.

  5. The Towers of Hanoi • By moving one disk at a time from peg to peg, the object of the puzzle is to reassemble the disks on Peg 3 in the original order. • At no point may a larger disk be placed on a smaller disk.

  6. The Towers of Hanoi Start 1 2 3

  7. The Towers of Hanoi Finish 1 2 3

  8. The Towers of Hanoi • There is a very simple recursive solution. • Reassemble the top 9 disks on Peg 2. • Move Disk 10 from Peg 1 to Peg 3. • Reassemble the top 9 disks on Peg 3.

  9. The Towers of Hanoi 1 2 3

  10. The Towers of Hanoi 1 2 3

  11. The Towers of Hanoi 1 2 3

  12. The Towers of Hanoi 1 2 3

  13. The Towers of Hanoi • But how does one reassemble the top 9 disks on Peg 2? • It is very simple to reassemble the top 9 disks on Peg 2. • Reassemble the top 8 disks on Peg 3. • Move Disk 9 from Peg 1 to Peg 2. • Reassemble the top 8 disks on Peg 2.

  14. The Towers of Hanoi 1 2 3

  15. The Towers of Hanoi 1 2 3

  16. The Towers of Hanoi 1 2 3

  17. The Towers of Hanoi 1 2 3

  18. The Towers of Hanoi • But how does one reassemble the top 8 disks on Peg 3? • It is very simple to reassemble the top 8 disks on Peg 3. • Reassemble the top 7 disks on Peg 2. • Move Disk 8 from Peg 1 to Peg 3. • Reassemble the top 7 disks on Peg 3.

  19. The Towers of Hanoi 1 2 3

  20. The Towers of Hanoi 1 2 3

  21. The Towers of Hanoi 1 2 3

  22. The Towers of Hanoi 1 2 3

  23. The Towers of Hanoi • But how does one reassemble the top 7 disks on Peg 2? • And so on…

  24. The Towers of Hanoi • Ultimately, the question becomes, how does one reassemble the top 1 disk on Peg 2? • Hmmm….

  25. The Towers of Hanoi 1 2 3

  26. The Towers of Hanoi 1 2 3

  27. The Towers of Hanoi • How many moves will it take? • Let mn be the number of moves to reassemble n disks. • Then • m1 = 1. • mn = 2mn – 1 + 1, for all n 2.

  28. Counting Strings • Let bk be the number of binary strings of length k that do not contain 11. • b0 = 1, {} • b1 = 2, {0, 1} • b2 = 3, {00, 01, 10} • b3 = 5, {000, 001, 010, 100, 101} • What is the pattern?

  29. Counting Strings • Consider strings of length k, for some k 2, that do not contain 11. • If the first character is 0, then the remainder of the string is a string of length k – 1 which does not contain 11. • If the first character is 1, then the next character must be 0 and the remainder is a string that does not contain 11.

  30. Counting Strings • k = 1: {0, 1}

  31. Counting Strings • k = 1: {0, 1} • k = 2: {00, 01, 10}

  32. Counting Strings • k = 1: {0, 1} • k = 2: {00, 01, 10} • k = 3: {000, 001, 010}  {100, 101}

  33. Counting Strings • k = 1: {0, 1} • k = 2: {00, 01, 10} • k = 3: {000, 001, 010, 100, 101}

  34. Counting Strings • k = 1: {0, 1} • k = 2: {00, 01, 10} • k = 3: {000, 001, 010, 100, 101} • k = 4: {0000, 0001, 0010, 0100, 0101}  {1000, 1001, 1010}

  35. Counting Strings • k = 1: {0, 1} • k = 2: {00, 01, 10} • k = 3: {000, 001, 010, 100, 101} • k = 4: {0000, 0001, 0010, 0100, 0101, 1000, 1001, 1010}

  36. Counting Strings • Therefore, • bk = bk – 1 + bk – 2, for all k 2. • The next few terms are • b3 = b2 + b1 = 5, • b4 = b3 + b2 = 8, • b5 = b4 + b3 = 13.

  37. Counting Binary Trees • How many binary trees are there with n nodes? • Let tn be the number binary trees with n nodes. • Clearly, t0 = 1, t1 = 1, and t2 = 2. n = 2 n = 1

  38. Counting Binary Trees • When n = 2, we have 5 trees:

  39. Counting Binary Trees • What is the recursive relation?

  40. Counting Binary Trees • What is the recursive relation? • t2 = 21 + 11 + 12 = 5

  41. Counting Binary Trees • When n = 2, we have 5 trees: 1 on left, 1 on right 0 on left, 2 on right 2 on left, 0 on right

  42. Counting Binary Trees • Following this pattern, we compute • t4 = 51 + 21 + 12 + 15 = 14. • t5 = 141 + 51 + 22 + 15 + 114 = 42. • t6 = 421 + 141 + 52 + 25 + 114 + 142 = 132. • and so on.

  43. Counting Paths • In the following figure, how many paths are there from the lower left corner to the upper right corner?

  44. Counting Paths • Let pn be the number of paths when the bottom has length n. • Then clearly, p0 = 1, p1 = 1, and p2 = 2.

  45. Counting Paths • When n = 3, …

  46. Counting Paths • When n = 3, …

  47. Counting Paths • When n = 3, …

  48. Counting Paths • When n = 3, …

  49. Counting Paths • When n = 3, …

  50. Counting Paths • When n = 3, …

More Related