Chapter 3
Chapter 3
Assistant Professor
IT-ICT Department, LJIET
Mr. Prayag Patel [email protected]
Recurrence Equation
▪ A Recurrence is a recursive description of a function, or
a description of a function in terms of itself.
▪ Many algorithms (Divide & conquer) are recursive in
nature.
▪ Recurrence equation is an equation that defines a
sequence recursively.
▪ Recurrence equation is normally in following form:
1) T(n) = T(n-1) + n for n > 0.
Recurrence Relation
2) T(0) = 0 Initial condition
1) 1 = 1 + 1 + 1 +……+ 1 = n
2) i = 1 + 2 + 3 +……+ n = n(n+1) /2
3) (ai + bi ) = ai + bi
4) c ai = c ai
5) 1 =n-k+1
Step-2 n T(n)
n=1 T(1) = T(1-1) + 1 = T(0) +1 = 0+1 = 1
Put initial condition
in equation and look n=2 T(2) = T(2-1) + 2 = T(1) +2 = 1 + 2 = 3
for the pattern. n=3 T(3) = T(3-1) + 3 = T(2) +3 = 3 + 3 = 6
n=4 T(4) = T(4-1) + 4 = T(3) +4 = 6 + 4 = 10
Step-2 n T(n)
n=1 T(1) = T(1-1) + 1 = T(0) +1 = 0+1 = 1
Put initial condition
in equation and look n=2 T(2) = T(2-1) + 1 = T(1) + 1 = 1 + 1 = 2
for the pattern. n=3 T(3) = T(3-1) + 1 = T(2) + 1 = 2 + 1 = 3
n=4 T(4) = T(4-1) + 1 = T(3) + 1 = 3 + 1 = 4
T(n) = T(n−1) + n
T(0) = 0
T(n) = T(n−1) + 1
T(0) = 0
Case - 1
Case - 2
Case - 3
p+1
p+1
Case-2(a): T(n)= Θ(nlogba log n) for p > -1 p+1
Case-2(b): T(n)= Θ(nlogba log log n) for p = -1
Case-2 (c): T(n)= Θ(nlogba) if p < -1
p+1
Θ (nlog22 log n)
= Θ (n log n)
p+1
p+1
p+1
Case-2(a): T(n)= Θ(nlogba log n) for p > -1 p+1
p+1
Ex-1 :
(1) if n = 1;
T(n) =
2T(n/2) + (n) if n > 1.
T(n/ 2 i)
(1)
(1)
(1) i = log2n
cn/2 cn/2
(1)
cn/2 cn/2 cn
(1)
cn/2 cn/2 cn
(1)
cn/2 cn/2 cn
(1) = n(lg n – 0 + 1) = n( lg n + 1) = n lg n + n
=n(lg n – 0 + 1)
=n( lg n + 1)
= nlg n + n
T(n)=O(n lg n)
Mr. Prayag Patel Department: IT/ICT-LJIET
Recurrence Tree Method
n2
n2 n2
(n/2) 2 (n/2) 2
n2 n2
n2/2
(n/2) 2 (n/2) 2
n2 n2
n2/2
(n/2) 2 (n/2) 2
= n2/ 2i
n2 n2
n2/2
h = lg n (n/2) 2 (n/2) 2
= n2/ 2i
n2/ 2i
T (n) =
r
a
m
T (n) = O(n2)
Mr. Prayag Patel Department: IT/ICT-LJIET
THANK YOU FOR
WATCHING!
Cuse 2:
tor P 1
fim)
Pt1
n)