Upload
rockers91
View
244
Download
0
Embed Size (px)
Citation preview
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
1/38
1
RECURRENCE
1. Sequence2. Recursively defined sequence3. Finding an explicit formula for
recurrence relation
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
2/38
2
Learning OutcomesYou should be able to solve
first-order and second-order linearhomogeneous recurrence relation withconstant coefficients
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
3/38
3
Preamble What is recurrence and how does it
relate to a sequence?
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
4/38
4
Sequences A sequenceis an ordered list of objects (or events). Like a set,
it contains members(also called terms) Sequences can be finiteor infinite.
2,4,6,8,
for i1 ai= 2i(explicit formula)infinite sequence with infinite distinct values
-1,1,-1,1, for i 1 bi= (-1)i
infinite sequence with finite distinct values
For 1
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
5/38
5
Ways to define sequence Write the first few terms:
3,5,7,
Use explicit formula for its nth term
an= 2n for n1
Use recursion How to define a sequence using a
recursion?
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
6/38
6
Recursively defined sequencesRecursion can be used to defined a sequence.
This requires:
A recurrence relation: a formula that relates each term ak
to some previous terms ak-1
, ak-2
,
ak = ak-1+ 2ak-2
The initial conditions: the values of the first few terms a0, a1,
Example: For all integers k 2, find the terms b2, b3and b4:bk= bk-1+ bk-2 (recurrence relation)
b0= 1 and b1= 3 (initial conditions)
Solution:b2= b1 + b0 = 3 + 1 = 4
b3= b2+ b1 = 4 + 3 = 7b4= b3+ b2 = 7 + 4 = 11
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
7/38
7
Explicit formula and
recurrence relation Show that the sequence 1,-1!,2!,-3!,4!,,(-1)nn!,
for n0, satisfies the recurrence relationsk= (-k)sk-1 for all integers k1.
The general term of the sequence: sn=(-1)nn!substitute k and k-1 for n to getsk=(-1)
kk! sk-1=(-1)k-1(k-1)!
Substitute sk-1 into recurrence relation:
(-k)sk-1= (-k)(-1)k-1
(k-1)!= (-1)k(-1)k-1(k-1)!= (-1)(-1)k-1 k(k-1)!= (-1)k k! = sk
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
8/38
8
Examples of recursively
sequence Famous recurrences
Arithmetic sequences: ak= ak-1+ d
e.g. 1,4,7,10,13,geometric sequences: ak= ark-1e.g. 1,3,9,27,Factorial: f(n) = n . f(n-1)
Fibonacci numbers: fk= fk-1+fk-21,1,2,3,5,8,Tower of Hanoi problem
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
9/38
9
Tower of Hanoi
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
10/38
10
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
11/38
11
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
12/38
12
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
13/38
13
Application of recurrence Analysis of algorithm containing recursive function such as
factorial function.
Algorithm f(n)
/input: A nonnegative integer/output: The value of n!If n = 0 return 1else return f(n-1)*n
No. of operations (multiplication) determines the efficiency ofalgo.
Recurrence relation is used to express the no. of operation inthe algorithm.
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
14/38
14
Solving Recurrence relation by
Iteration It is helpful to know an explicit formula for a
sequence. An explicit formula is called a solutionto the
recurrence relation Most basic method is iteration- start from the initial condition- calculate successive terms until a patterncan be seen- guess an explicit formula
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
15/38
15
Some examplesLet a0,a1,a2, be the sequence defined recursively as follows: For
all integers k1,(1) ak= ak-1+2(2) a0= 1
Use iteration to guess an explicit formula for the sequence.a0=1a1=a0+2a2=a1+2=(1+2)+2 = 1+2.2a3=a2+2=(1+2.2)+2 = 1+3.2
a4=a3+2=(1+3.2)+2 = 1+4.3.Guess: an=1+n.2=1+2nThe above sequence is an arithmetic sequence.
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
16/38
16
Geometric Sequence
Let r be a fixed nonzero constant, and suppose a sequencea0,a1,a2, is defined as follows:
ak= rak-1for all integers k 1a0= a
Use iteration to guess an explicit formula for the sequencea0=aa1=ra0=raa2=ra1=r(ra)=r
2aa3=ra2=r(r
2a)=r3a
Guess: an=rna = arn for all integers n0The above sequence is geometric sequence and r is a common
ratio.
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
17/38
17
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
18/38
18
Explicit formula for tower of Hanoi
mn= 2n1. (exponential order)
To move 1 disk takes 1 second
m64= 2641 = 1.844674 * 1019 seconds
= 5.84542 * 1011years
= 584.5 billion years.
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
19/38
19
Second-Order Linear Homogeneous withconstant coefficients
A second-order linear homogeneousrecur. relation with c.c. is a recur.
relation of the formak= Aak-1+ Bak-2for all integers k some fixed integer,
where A and B are fixed real numberswith B 0.
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
20/38
20
Terminology
ak= Aak-1+ Bak-2 Second order: ak contains the two previous
terms Linear: ak-1 and ak-2appear in separate terms
and to the first power
Homogeneous: total degree of each term is
the same (no constant term) Constant coefficients: A and B are fixed real
numbers
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
21/38
21
Examples
Second-Order Linear Homogeneous with constantcoefficients
ak= 3a
k-1+ 2a
k-2 - yes.
bk= bk-1+ bk-2+ bk-3 - no
dk= (dk-1)2+ dk-1dk-2 - no; not linear
ek= 2ek-2 - yes; A = 0, B = 2.
fk= 2fk-1+ 1 - no; not homogeneous
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
22/38
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
23/38
23
Using the characteristic equation tofind sequences
Example: Consider the following recurrence relationak = ak-1+2ak-2for all k >= 2.Find sequences that satisfy the relation.Solution: For the given relation, A=1 and B=2.Relation is satisfied by the sequence 1,t,t2,t3, iff t satisfies the
characteristic equationt2AtB = 0 ort2t2 = 0(t2)(t + 1) = 0.
t = 2 or t = -1.Sequences: 1,2,22,23, and
1,-1,(-1)2,(-1)3, or 1,-1,1,-1, ,(-1)n,
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
24/38
24
Linear combination ofsequences
Lemma
If r0,r1,r2,,rn,.. and s0,s1,s2,,sn, are sequences thatsatisfy the same second-order linear homogeneous
recurrence relation with c.c., and if C and D are anynumbers, then the sequence a0,a1,a2,defined by the formula
an= C.rn + D.snfor all integer n>=0
also satisfies the same recurrence relation. C and D can be calculated using initial conditions.
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
25/38
25
Two possible solutions
For the characteristic equation
t2AtB = 0
there are two possible solutions:
- Distinct-roots case
- Single-root case
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
26/38
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
27/38
27
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
28/38
28
Steps for finding explicitformula
1. Form the characteristic equation.
2. Solve the equationlet r and s be theroots. ( r s)
3. Set up an explicit formula:
ak= C.rk+ D.sk
4. Find C and D using initial conditions.
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
29/38
29
Quadratic equation
ax2+ bx + c = 0
x = [-b +- (b24.a.c)]/(2.a)
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
30/38
30
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
31/38
31
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
32/38
32
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
33/38
33
Single-Root Case
Two sequences that satisfy the relation
ak= A.ak-1+B.ak-2
where r is the root of t
2
- A.t - B = 0.Explicit formula for the new sequence
an= C.rn+ D.nrn
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
34/38
34
Example
A sequence b0, b1, b2, satisfies the rec. relation
bk= 4bk-14bk-2for k>=2 with initial conditions b0=1and b
1
=3.
Find explicit formula for the sequence.
Solution: A=4 and B=-4
Charac eq: t24t +4 =0
(t-2)2
=0. t=2.Seq: 1,2,22, , 2n,..
0,2,2.22,3.23,,n.2n,
Explicit formula: bn= C.rn+ D.nrn
= C.2n+ D.n2n
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
35/38
35
Example
bn= C.2n+ D.n2n
b0= 1 = C.20+ D.0.20= C
b1= 3 = C.2 + D.2 3 = 1.2 + 2D
Hence D = .
Therefore bn= 2n+ (1/2).n.2n
= 2n (1+ n/2) for integer n>=0. Sequence: 1,3,8,20,
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
36/38
36
Question
?????
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
37/38
37
Summary
How to express the sequence
Find explicit formula for first-order
recurrence relation
Find explicit formula for second-orderrecurrence relation (distinct and single
root)
8/10/2019 Discrete Structure Chapter 6-Recurrence Relation
38/38
38
THANK YOU