190 likes | 367 Views
13.2 Recursive Definitions. Objective Provide the recursive definition for sequences; 2) Identify the type of a sequence from a recursive definition. Recursively Defined Sequences. Often it is difficult to express the members of an object or numerical sequence explicitly.
E N D
13.2 Recursive Definitions • Objective • Provide the recursive definition for sequences; • 2) Identify the type of a sequence from a recursive definition.
Recursively Defined Sequences Often it is difficult to express the members of an object or numerical sequence explicitly. Example: The Fibonacci sequence: {fn } = 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.
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: a1 = 1, (initial condition) an= an–1 + 3 for n≥2 (recurrence relation) Example: Recursive definition for {fn }: f0= 0, f1 = 1 (initial condition) fn= fn – 1 + fn – 2 for n > 1. (recurrence relation)
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: an= 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.
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)
Tower of Hanoi: Move disks from left pole to right pole 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 Pole A Pole B Pole C Pole A Pole B Pole C
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 andenote 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 a1 = 1 and all done.
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 an–1moves, the recursive procedure (2) needs 1 moves, and recursive procedure (3) still takes an–1moves. So the recursive definition for the Tower of Hanoi is an= an–1 + 1 + an–1 for n ≥2 or an= 2an–1 + 1 for n ≥2
Recursive Formula for Compound Interest Example: Suppose $10K is deposited in an account paying 3% interest compounded annually. For each positive integer n, let A0 = the initial amount deposited; An= the amount on deposit at the end of year n. Find a recursive relation for A0 , A1 , A2 ,… assuming no additional deposits or withdrawals. We have the following recursive formula: A0 = 10,000 An= An-1 + 0.03An-1 = 1.03An-1 for n≥1
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: A0 = 10,000 An= 1.03An-1forn≥1 The explicit formula is An= 10000(1.03)nforn≥0 Note: this formula can be generalized to any geometric sequence.
Finding an Explicit Formula for a Recursively Defined Sequence Example (cont.) Suppose the sequence is given by the following recursive relation: a0 = 3 an= an-1 + 4 for n≥1 Then the explicit formula is an= 3 + 4nforn≥0 • Note: this formula can be generalized to any arithmetic sequence.
Finding an Explicit Formula for a Recursively Defined Sequence Example (cont.) Recall the recursive formula for the Hanoi Tower example: a1 = 1 an= 2an-1 + 1 forn≥2 • How to get explicit formula? • Compute the first few terms of this sequence: a1 = 1 a2 = 3a3 = 7 a4 = 15 a5 = 31 a6 = 63 Based on the pattern, an= 2n – 1 forn≥1 The explicit definition for Hanoi Tower problem is very hard. = 21 – 1, = 23 – 1, = 22 – 1, = 25 – 1, = 26 – 1, = 24 – 1,
Note the difference between explicit definition and recursive definition • Explicit definition An explicit definition gives an as a function of n . • Recursive definition Gives the initial term(s) and a recursive equation that tells how an is related to one or more of the preceding terms.
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: • Suppose {an} is an arithmetic sequence with common difference d. Then the • explicit definition is an= a1 + (n – 1)d • recursive definition 1 is a1 = , an = an-1 + d • recursive definition 2 is a1=, a2 = , an= 2an-1 – an-2 • 2. Suppose {bn} is a geometric sequence with common ration r. Then the • explicit definition is bn = b1rn-1 • recursive definition 1 is b1= ,bn = rbn-1 • Recursive definition 2 is
Example • P. 482 #23. • Suppose that Sn represents the number of dots in an n by n square array. Give a recursion equation that tells how Sn+1 is related to Sn. • S1 = 1, Sn+1 = Sn + n + n +1 • S1 = 1, Sn+1= Sn + 2n + 1 forn ≥ 1 n 1 n Sn 1 1 • How to get explicit formula? • Compute the first few terms of this sequence: S1 = 1 S2 = 4S3 = 9 S4 = 16 S5 = 25 S6 = 36 Based on the pattern, Sn= n2forn≥1.
Note Some sequences may have more than one recursive definition: For example, any arithmetic sequence with common difference d can be expressed as a1 = c an= an-1 + dfor n≥2 Or, it may also be defined as a1 = b, a2 = c an= 2an-1 – an-2forn≥3.
Note Some sequences may have more than one recursive definition: For example, any geometric sequence with common ratio r can be expressed as a1 = c an= ran-1, for n≥2 Or, it may also be defined as a1 = b, a2 = c an= (an-1)2/an-2forn≥3.
Assignment P. 481 #1 – 22, 24, 29, 30, 32