Recursively Defined Sequences Lecture 35 Section 8.1 Wed, Mar 23, 2005.

Slides:



Advertisements
Similar presentations
Analysis of Algorithms II
Advertisements

Tower of Hanoi Tower of Hanoi is a mathematical puzzle invented by a French Mathematician Edouard Lucas in The game starts by having few discs stacked.
Week 6 - Wednesday CS322.
Chapter Recurrence Relations
Chapter 6 Advanced Counting 6.1 Recurrence Relations.
COSC 2006 Data Structures I Recursion III
CS 2210 (22C:19) Discrete Structures Advanced Counting
Kavita Math231 Recursion and Iteration. Kavita Math231 We use Recursion when we have to perform a complex task that can be broken into the several subtasks.
Chapter 10 Recursion Instructor: alkar/demirer. Copyright ©2004 Pearson Addison-Wesley. All rights reserved.10-2 Recursive Function recursive functionThe.
Slides prepared by Rose Williams, Binghamton University Chapter 11 Recursion.
Recursion. 2 CMPS 12B, UC Santa Cruz Solving problems by recursion How can you solve a complex problem? Devise a complex solution Break the complex problem.
Recursive Algorithms Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Recursion.
1 Section 6.1 Recurrence Relations. 2 Recursive definition of a sequence Specify one or more initial terms Specify rule for obtaining subsequent terms.
Recursion Lecture 17: Nov 11. Quiz int hello(int n) { if (n==0) return 0; else printf(“Hello World %d\n”,n); hello(n-1); } 1.What would the program do.
6.Advanced Counting Techniques 1 Copyright M.R.K. Krishna Rao 2003 Ch 6. Recurrence Relations A recurrence relation for the sequence {a n } is an equation.
Chapter 8 With Question/Answer Animations 1. Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence.
Analysis of Recursive Algorithms October 29, 2014
Recursion Apan Qasem Texas State University Spring 2011.
Copyright © Cengage Learning. All rights reserved.
Applied Discrete Mathematics Week 9: Relations
Advanced Counting Techniques
OBJ: To use a problem solving plan to solve problems.
Department of Computer Science Data Structures Using C++ 2E Chapter 6: Recursion Learn about recursive Definitions Algorithms Functions Explore the base.
Chapter 8. Section 8. 1 Section Summary Introduction Modeling with Recurrence Relations Fibonacci Numbers The Tower of Hanoi Counting Problems Algorithms.
13.2 Recursive Definitions Objective 1) Provide the recursive definition for sequences; 2) Identify the type of a sequence from a recursive definition.
Fall 2015 COMP 2300 Discrete Structures for Computation Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1.
Solving Recurrence Lecture 19: Nov 25. Some Recursive Programming (Optional?)
CSE 2813 Discrete Structures Recurrence Relations Section 6.1.
Module #20 - Recurrences 1 Ch. 7 Recurrence Relations Rosen 6 th ed., §§7.1.
R. Johnsonbaugh Discrete Mathematics 7 th edition, 2009 Chapter 7 Recurrence Relations Instructor Tianping Shuai.
15.1 CompSci 102© Michael Frank Today’s topics Recurrence relationsRecurrence relations –Stating recurrences –LiHoReCoCo Reading: Sections Reading:
Solving Second-Order Recursive Relations Lecture 36 ½ Section 8.3 Wed, Apr 19, 2006.
Review Introduction to Searching External and Internal Searching Types of Searching Linear or sequential search Binary Search Algorithms for Linear Search.
1 CO Games Development 1 Week 11 Search Methods Gareth Bellaby.
Section 2.4. Section Summary Sequences. Examples: Geometric Progression, Arithmetic Progression Recurrence Relations Example: Fibonacci Sequence Summations.
Module #1 - Logic 1 Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen Recurrence.
Read a problem and make a plan EXAMPLE 1 Running You run in a city where the short blocks on north-south streets are 0.1 mile long. The long blocks on.
Chapter 8 With Question/Answer Animations. Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence.
Recurrence Relation Models
after UCI ICS/Math 6A, Summer AdvancedCounting -1 Recurrence Relations (RRs) A “Recurrence Relation”
Sequences and Summations Section 2.4. Section Summary Sequences. – Examples: Geometric Progression, Arithmetic Progression Recurrence Relations – Example:
Chapter 6.1: Recurrence Relations Discrete Mathematical Structures: Theory and Applications.
Discrete Mathematics Recurrence Relations Chapter 5 R. Johnsonbaugh
Read a problem and make a plan EXAMPLE 1 Running You run in a city where the short blocks on north-south streets are 0.1 mile long. The long blocks on.
22C:19 Discrete Math Advanced Counting Fall 2010 Sukumar Ghosh.
1 Recursion Recursion is a powerful programming technique that provides elegant solutions to certain problems. Chapter 11 focuses on explaining the underlying.
1 Examples of Recursion Instructor: Mainak Chaudhuri
1 Copyright © Cengage Learning. All rights reserved. 6. The Trigonometric Functions 6.7 Application Problems.
Solving Recurrence Relations by Iteration Lecture 36 Section 8.2 Mon, Apr 17, 2006.
Discrete Mathematics Lecture # 22 Recursion.  First of all instead of giving the definition of Recursion we give you an example, you already know the.
1 Recursion Recursive function: a function that calls itself (directly or indirectly). Recursion is often a good alternative to iteration (loops). Its.
Example 1 Read a problem and make a plan
chap10 Chapter 10 Recursion chap10 2 Recursive Function recursive function The recursive function is a kind of function that calls.
1 In this puzzle, the player begins with n disks of decreasing diameter placed one on top of the other on one of three pegs of the game board. The player.
Tower of Hanoi Tower of Hanoi is a mathematical puzzle invented by a French Mathematician Edouard Lucas in The game starts by having few discs stacked.
Recursively Defined Sequences Lecture 40 Section 8.1 Wed, Apr 11, 2007.
Lecture 11 Recursion. A recursive function is a function that calls itself either directly, or indirectly through another function; it is an alternative.
Tower of Hanoi problem: Move the pile of rings from one peg to another
Chapter 10 Recursion Instructor: Yuksel / Demirer.
Recursive Thinking Chapter 9 introduces the technique of recursive programming. As you have seen, recursive programming involves spotting smaller occurrences.
Java Software Structures: John Lewis & Joseph Chase
Recursive Thinking Chapter 9 introduces the technique of recursive programming. As you have seen, recursive programming involves spotting smaller occurrences.
Solving Recurrence Relations by Iteration
Tower of Hanoi problem: Move the pile of rings from one peg to another
CS 2210 Discrete Structures Advanced Counting
Recursion: The Mirrors
Chapter 3 :Recursion © 2011 Pearson Addison-Wesley. All rights reserved.
Tower of Hanoi problem: Move the pile of rings from one peg to another
Recursively Defined Sequences
Presentation transcript:

Recursively Defined Sequences Lecture 35 Section 8.1 Wed, Mar 23, 2005

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. The initial conditions are equations that specify the values of the first several terms a 0, …, a n – 1.

Recursive Sequence Define a sequence {a k } by a 0 = 2, a 1 = 3, a k = a k – 1 + 2a k – 2, for all k  2. The next few terms are a 2 = 7, a 3 = 13, a 4 = 27.

The Towers of Hanoi The game board has three pegs, Peg 1, Peg 2, Peg 3, and 10 disks. Initially, the 10 disks are stacked on Peg 1, each disk smaller than the disk below it. By moving one disk at a time from peg to peg, reassemble the disks on Peg 3 in the original order. At no point may a larger disk be placed on a smaller disk.

The Towers of Hanoi 123 Start

The Towers of Hanoi 123 Finish

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. But how does one reassemble the top 9 disks on Peg 2?

The Towers of Hanoi 123

123

123

123

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. But how does one reassemble the top 8 disks on Peg 3?

The Towers of Hanoi 123

123

123

123

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. But how does one reassemble the top 7 disks on Peg 2? Etc.

The Towers of Hanoi 123

123

123

123

Ultimately, the question becomes, how does one reassemble the top 1 disk on Peg 2? That really is simple: just move it there.

The Towers of Hanoi 123

123

How many moves will it take? Let a n be the number of moves to reassemble n disks. Then a 1 = 1. a n = 2a n – 1 + 1, for all n  2.

Future Value of an Annuity Begin with an initial deposit of $d. At the end of each month Add interest at a monthly interest rate r. Deposit an additional $d. Let a k denote the value at the end of the k- th month. a 0 = d, a k = (1 + r)a k – 1 + d, for all k  1.

Future Value of an Annuity The first few terms are a 0 = d. a 1 = (1 + r)a 0 + d = 2d + rd. a 2 = (1 + r)a 1 + d = 3d + 3rd + r 2 d. a 3 = (1 + r)a 2 + d = 4d + 6rd + 4r 2 d + r 3 d. What is the pattern?

Future Value of an Annuity We might guess that the nonrecursive formula is a n = ((1 + r) n + 1 – 1)(d/r). We will verify this guess later.

Counting Strings Let  = {0, 1}. Let a k be the number of strings in  * of length k that do not contain 11. a 0 = 1, {  } a 1 = 2, {0, 1} a 2 = 3, {00, 01, 10} a 3 = 5, {000, 001, 010, 100, 101} What is the pattern?

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.

Counting Strings k = 1: {0, 1}

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

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

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

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}

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}

Counting Strings Therefore, a k = a k – 1 + a k – 2, for all k  2. The next few terms are a 3 = a 2 + a 1 = 5, a 4 = a 3 + a 2 = 8, a 5 = a 4 + a 3 = 13.

Counting r-Partitions An r-partition of a set is a partition of the set into r nonempty subsets. Let A be a set of size n. Let a n, r be the number of distinct r- partitions of A. Special cases a n, n = 1 for all n  1. a n, 1 = 1 for all n  1.

Counting r-Partitions Let A = {a, b, c, d}. a 4, 2 = 7 since the 2-partitions are {{a}, {b}, {c, d}} {{a}, {c}, {b, d}} {{a}, {d}, {b, c}} {{b}, {c}, {a, d}} {{b}, {d}, {a, c}} {{c}, {d}, {a, b}}

Counting r-Partitions Consider an r-partition of a set A. Let x  A. Either x is in a set {x} by itself or it isn’t. If it is, then the remaining sets form an (r – 1)-partition of A – {x}. If it isn’t, then if we remove x, we have an r-partition of A – {x}.

Counting r-Partitions The 3-partitions that contain { a }. {{a}, {b}, {c, d}} {{a}, {c}, {b, d}} {{a}, {d}, {b, c}} The 3-partitions that do not contain { a }. {{b}, {c}, {a, d}} {{b}, {d}, {a, c}} {{c}, {d}, {a, b}}

Counting r-Partitions The 3-partitions that contain { a }. {{a}, {b}, {c, d}}  {{b}, {c, d}} {{a}, {c}, {b, d}}  {{c}, {b, d}} {{a}, {d}, {b, c}}  {{d}, {b, c}} The 3-partitions that do not contain { a }. {{b}, {c}, {a, d}} {{b}, {d}, {a, c}} {{c}, {d}, {a, b}} Distinct 2-partitions of {b, c, d}

Counting r-Partitions The 3-partitions that contain { a }. {{a}, {b}, {c, d}}  {{b}, {c, d}} {{a}, {c}, {b, d}}  {{c}, {b, d}} {{a}, {d}, {b, c}}  {{d}, {b, c}} The 3-partitions that do not contain { a }. {{b}, {c}, {a, d}}  {{b}, {c}, {d}} {{b}, {d}, {a, c}}  {{b}, {d}, {c}} {{c}, {d}, {a, b}}  {{c}, {d}, {b}} Three copies of same 3-partition of {b, c, d}

Counting r-Partitions In fact, we get the same r-partition of A – {x} that we would get had x been a member of any other set in the partition. Thus, each r-partition of A – {x} gives rise to r r-partitions of A. Therefore, a n, r = a n – 1, r – 1 + r  a n – 1, r, for all n  1 and for all r, 1 < r < n.

Counting r-Partitions Compute a 4, 2. and a 5, 2. a 4, 2 = a 3, 1 + 2a 3, 2 = 1 + 2(a 2, 1 + 2a 2, 2 ) = 1 + 2(1 + 2  1) = 7. a 5, 2 = a 4, 1 + 2a 4, 2 =  7 = 15.

Taxicab Routes In a city, streets run either east-west or north-south. They form a grid, like graph paper. Let a m, n denote the number of routes that a taxicab may follow to reach a point that is m blocks east and n blocks north of its current location. Assume the cab travels only east and north.

Taxicab Routes Special cases a 0, n = 1 for all n  0. a m, 0 = 1 for all m  0. One block from the destination, he is either one block south or one block west.

One Block South 4  6 Grid One block south

One Block West 4  6 Grid One block north

Taxicab Routes If he is one block south of the destination, then there are a m,n – 1 routes to get to that point, followed by one route (north) to get to the destination.

One Block South 4  6 Grid

One Block South 3  6 Grid

Taxicab Routes If he is one block west of the destination, there there are a m – 1,n routes to get to that point, followed by one route (east) to get to the destination.

One Block West 4  6 Grid

One Block West 4  5 Grid

Taxicab Routes Therefore, a m, n = a m – 1, n + a m, n – 1, for all m, n  1. Calculate the first few terms.