Download Recursively Defined Sequences - Discrete Mathematical Structures - Lecture Slides and more Slides Discrete Mathematics in PDF only on Docsity!
Chapter 8
Recursion
Recursively Defined Sequences
Defining Recursion
- Recursion requires
- recurrence relation relates later terms in the sequence to earlier terms and
- initial conditions, values of the first few terms of the sequence.
- Example b0, b 1 , b 2 , … For all integers k>= 2,
- b (^) k = bk-1 + bk-2 (recurrence relation)
- b 0 = 1, b 1 = 3 (initial conditions) b 2 = b2-1 + b2-2 = b1 + b0 = 3 + 1 = 4 b 3 = b3-1 + b3-2 = b2 + b1 = 4 + 3 = 7 b 5 = b5-1 + b5-2 = b4 + b3 = 11 + 7 = 18
Recursion
• Definition:
- A recurrence relation for a sequence a 0 , a 1 , a 2 ,… is
a formula that relates each term a k to ceratin of its
predecessors a k-1, a k-2, … , a k-I, where I is an integer
and k is any integer greater than or equal to i.
- The initial conditions for such a recurrence
relation specify the values of a 0 , a 1 , a 2 ,…,a i-1, if I is
a fixed integer, or a 0 , a 1 , a 2 ,…,a m , where m is an
integer with m>=0, if i depends on k.
Equivalent Recursion
• There is more than one way to setup a recursive
sequence!
- for all k>=1, s (^) k = 3sk-1 – 1
- for all k>=0, s (^) k+1 = 3s (^) k – 1
• Are the two sequences equivalent?
- show the results of the sequence for terms:
- starting at k = 1: s 1 = 3s 0 – 1, s 2 = 3s 1 – 1, s 3 = 3s 2 – 1
- starting at k = 0: s (^) 0+1 = 3s 0 – 1, s (^) 1+1 = 3s 1 – 1, …
- change first term to second by adjusting first k
- for all k>=1, s (^) k = 3s (^) k-1 – 1 => k start at 0 (k≥0) sk+1 =3s (^) k – 1
- same as the second form.
Example
- Show that sequence given satisfies a recurrence
relation:
- 1, -1!, 2!, -3!, 4!, …, (-1) nn!, …, for n≥0 is equivalent to sk = (-k)sk-1 for k≥
- General term of the seq sn starting with s 0 = 1, then sn = (-
- nn! for n≥
- substitute for k and k-1: sk = (-1) kk! , sk-1 = (-1) k-1(k-1)! (-k)s (^) k-1 = (-k)[(-1) k-1(k-1)!] (s (^) k defined above) = (k)(-1)(-1) k-1(k-1)! = (k)(-1) k(k-1)! = (-1) k(k)(k-1)! = (-1) k^ k! = sk
Towers of Hanoi
disks with holes in the
center that are stacked
from largest diameter to
smallest on the first of
three poles. Move the
stacked disk from one pole
to another.
- Rules: a larger disk cannot
be placed on top of a
smaller disk at any time.
Towers of Hanoi
- Recursive Solution
- Transfer the top k-1 disks from pole A to pole B. (Note: k>2 requires a number of moves.)
- Move the bottom disk from pole A to pole C.
- Transfer the top k-1 disks from pole B to pole C. (Again, if k>2, execution of this step will require more than one move.)
Towers of Hanoi
1. mk = 2mk-1 + 1 (recurrence relation)
2. m 1 = 1 (initial condition)
m 2 = 2m 1 + 1 = 3 m 3 = 2m 2 + 1 = 7 m 4 = 2m 3 + 1 = 15 … m 6 = 2m 5 + 1 = 63
Fibonacci
• Leonardo of Pisa was the greatest mathematician
of the 13 th^ century.
• Proposed the following problem:
- A single pair of rabbits (male/female) is born at the
beginning of a year. Assuming the following
conditions:
- Rabbit pairs are not fertile during their first month of life but thereafter give birth to one new male/female pair at the end of every month.
- No rabbits die
- How many rabbits will there be at the end of the
year?
Fibonacci
- for n ≥1, Fn = num of pairs alive at month n
- F 0 = the initial number of pairs
- F 0 = 1
- F (^) k = F (^) k-1 + F (^) k-
- Fibonacci Sequence
- F (^) k = F (^) k-1 + F (^) k-2 (recurrence relation)
- F 0 = 1, F 1 = 1 (initial condition) F 2 = F 1 + F 0 = 1+1 = 2 F 3 = F 2 + F 1 = 2+1 = 3 F 4 = F 3 + F 2 = 3+2 = 5 … F 12 = F 11 + F 10 = 144 + 89 = 233
Compound Interest
• Compute compound interest on principle
value using recursive sequence.
• $100,000 principle, earning 4% per year, how
much would you have in 21 years.
amt in account end of a year
=
amt in account at end of previous year
+
interest earned on account during year
=
amt in account at end of previous year
(0.04)* amt in account previous year A (^) n = amt in account at end of year n A 0 = initial amount (principle) A (^) k = A (^) k-1 + (0.04)Ak- A (^) k = (1.04)Ak-
Example
• Given $10,000, How much will the account be
work at the end of one year with a interest
rate of 3% compounded quarterly?
- Pk = Pk-1 (1+0.0075) = Pk-1(1.0075), integers k≥
- P 0 = 10,
- P 1 = 1.0075P 0 =1.007510,000 =10,075.
- P 2 = 10,150.
- P 3 = 10,226.
- P 4 = 10,303.