Presentation is loading. Please wait.

Presentation is loading. Please wait.

13.2 Recursive Definitions Objective 1) Provide the recursive definition for sequences; 2) Identify the type of a sequence from a recursive definition.

Similar presentations


Presentation on theme: "13.2 Recursive Definitions Objective 1) Provide the recursive definition for sequences; 2) Identify the type of a sequence from a recursive definition."— Presentation transcript:

1 13.2 Recursive Definitions Objective 1) Provide the recursive definition for sequences; 2) Identify the type of a sequence from a recursive definition.

2 Recursively Defined Sequences Often it is difficult to express the members of an object or numerical sequence explicitly. Example: The Fibonacci sequence: {f n } = 0,1,1,2,3,5,8,13,21,34,55,… There may, however, be some “local” connections that can give rise to a recursive definition – a formula that expresses higher terms in the sequence, in terms of lower terms.

3 Recursively Defined Sequences To define a sequence recursively, it must consists two parts: give initial condition(s), i.e., the value(s) of the first (few) term(s) explicitly (that tells where the sequence starts); give a recurrence relation, i.e., an equation that relates any term in the sequence to the preceding term(s). Example: Define the following sequence recursively: 1, 4, 7, 10, 13, … Solution: a 1 = 1, (initial condition) a n = a n–1 + 3 for n≥2(recurrence relation) Example: Recursive definition for {f n }: f 0 = 0, f 1 = 1 (initial condition) f n = f n – 1 + f n – 2 for n > 1. (recurrence relation)

4 Recursively defined sequences In 13.1 and 13.3, we have learned the explicit definitions for sequences. The same sequence can be defined explicitly as: Example: Define the following sequence explicitly: 1, 4, 7, 10, 13, … Solution: a n = 1 + (n – 1)  3 = 3n – 2 We learned from this example that it may have both explicit definition and recursive definition for the same sequence.

5 Recursion is one of the central ideas of computer science To solve a problem recursively Break it down into smaller subproblems each having the same form as the original problem; When the process is repeated many times, the last of the subproblems are small and easy to solve; The solutions of the subproblems can be woven together to form a solution to the original problem. Example: The tower of Hanoi (P. 484 #31)

6 RULES: You may only move one disk at a time. A disk may only be moved to one of the three columns. You must never place a larger disk on top of a smaller disk. INITIAL STATE GOAL STATE Tower of Hanoi: Move disks from left pole to right pole Pole A Pole B Pole C

7

8 The Tower of Hanoi How to generalize the procedure to n disks? How many moves are required? Recursive procedure: (1) Transfer the top n – 1 disks from pole A to pole B (2) Move the bottom disk from pole A to pole C (3) Transfer the top n – 1 disks from pole B to pole C Let a n denote the number of moves needed to transfer a tower of n disks from one pole to another using the above procedure. Then we have the following recursive relations for counting the moves: If n = 1 (or only 1 disk), then a 1 = 1 and all done.

9 The Tower of Hanoi Recursive procedure: (1) Transfer the top n – 1 disks from pole A to pole B (2) Move the bottom disk from pole A to pole C (3) Transfer the top n – 1 disks from pole B to pole C If n  2, then the recursive procedure (1) requires a n–1 moves, the recursive procedure (2) needs 1 moves, and recursive procedure (3) still takes a n–1 moves. So the recursive definition for the Tower of Hanoi is a n = a n–1 + 1 + a n–1 for n ≥ 2 or a n = 2a n–1 + 1 for n ≥ 2

10 Recursive Formula for Compound Interest Example: Suppose $10K is deposited in an account paying 3% interest compounded annually. For each positive integer n, let A 0 = the initial amount deposited; A n = the amount on deposit at the end of year n. Find a recursive relation for A 0, A 1, A 2,… assuming no additional deposits or withdrawals. We have the following recursive formula: A 0 = 10,000 A n = A n-1 + 0.03  A n-1 = 1.03  A n-1 for n≥1

11 Finding an Explicit Formula for a Recursively Defined Sequence It is often helpful to know an explicit formula for the sequence, especially if you need to compute terms with very large subscripts; to examine general properties of the sequence. Example Recall the recursive formula for the compound interest example: A 0 = 10,000 A n = 1.03  A n-1 for n≥1 The explicit formula is A n = 10000  (1.03) n for n≥0 Note: this formula can be generalized to any geometric sequence.

12 Example (cont.) Suppose the sequence is given by the following recursive relation: a 0 = 3 a n = a n-1 + 4 for n≥1 Then the explicit formula is a n = 3 + 4  n for n≥0 Note: this formula can be generalized to any arithmetic sequence. Finding an Explicit Formula for a Recursively Defined Sequence

13 Example (cont.) Recall the recursive formula for the Hanoi Tower example: a 1 = 1 a n = 2a n-1 + 1 for n≥2 How to get explicit formula? Compute the first few terms of this sequence: a 1 = 1 a 2 = 3 a 3 = 7 a 4 = 15 a 5 = 31 a 6 = 63 Based on the pattern, a n = 2 n – 1 for n≥1 The explicit definition for Hanoi Tower problem is very hard. Finding an Explicit Formula for a Recursively Defined Sequence = 2 1 – 1, = 2 2 – 1, = 2 3 – 1, = 2 4 – 1, = 2 5 – 1,= 2 6 – 1,

14 Note the difference between explicit definition and recursive definition 1.Explicit definition An explicit definition gives a n as a function of n. 2.Recursive definition Gives the initial term(s) and a recursive equation that tells how a n is related to one or more of the preceding terms.

15 One Important Note For a sequence, it may have both explicit definition and recursive definition. It also may have more than one recursive definition(equation). Examples are: 1.Suppose {a n } is an arithmetic sequence with common difference d. Then the explicit definition is a n = a 1 + (n – 1)d recursive definition 1 is a 1 = , a n = a n-1 + d recursive definition 2 is a 1 = , a 2 = , a n = 2a n-1 – a n-2 2. Suppose {b n } is a geometric sequence with common ration r. Then the explicit definition is b n = b 1 r n-1 recursive definition 1 is b 1 = , b n = rb n-1 Recursive definition 2 is

16 Example P. 482 #23. 1.Suppose that S n represents the number of dots in an n by n square array. Give a recursion equation that tells how S n+1 is related to S n. S 1 = 1, S n+1 = S n + n + n +1 S 1 = 1, S n+1 = S n + 2n + 1 for n ≥ 1 n n 1 1 1 SnSn How to get explicit formula? Compute the first few terms of this sequence: S 1 = 1 S 2 = 4 S 3 = 9 S 4 = 16 S 5 = 25 S 6 = 36 Based on the pattern, S n = n 2 for n≥1.

17 Note Some sequences may have more than one recursive definition: For example, any arithmetic sequence with common difference d can be expressed as a 1 = c a n = a n-1 + d for n≥2 Or, it may also be defined as a 1 = b, a 2 = c a n = 2a n-1 – a n-2 for n≥3.

18 Note Some sequences may have more than one recursive definition: For example, any geometric sequence with common ratio r can be expressed as a 1 = c a n = r a n-1, for n≥2 Or, it may also be defined as a 1 = b, a 2 = c a n = (a n-1 ) 2 /a n-2 for n≥3.

19 Assignment P. 481 #1 – 22, 24, 29, 30, 32


Download ppt "13.2 Recursive Definitions Objective 1) Provide the recursive definition for sequences; 2) Identify the type of a sequence from a recursive definition."

Similar presentations


Ads by Google