CSE 203-Recurrence-Analysis
CSE 203-Recurrence-Analysis
What is a recurrence?
• A recurrence is an equation or inequality that describes a function in
terms of its value on smaller inputs.
Recurrence can take
many forms.
Equal split
• Guess O(n3) .
• Assume that T(k) £ ck3 for k < n .
• Prove T(n) £ cn3 by induction.
Example (continued)
• We must also handle the initial conditions,
that is, ground the induction with base
cases.
• Base: T(n) = Q(1) for all n < n0, where n0
is a suitable constant.
• For 1 £ n < n0, we have “Q(1)” £ cn3, if
we pick c big enough.
T(n)
Example of recursion tree
Solve T(n) = T(n/4) + T(n/2) + n2:
n2
T(n/4) T(n/2)
Example of recursion tree
Solve T(n) = T(n/4) + T(n/2) + n2:
n2
(n/4)2 (n/2)2
n2
(n/4)2 (n/2)2
Q(1)
Example of recursion tree
Solve T(n) = T(n/4) + T(n/2) + n2:
n2
n2
(n/4)2 (n/2)2
Q(1)
Example of recursion tree
Solve T(n) = T(n/4) + T(n/2) + n2:
n2
n2
(n/4)2 (n/2)2 5 n2
16
(n/16)2 (n/8)2 (n/8)2 (n/4)2
…
Q(1)
Example of recursion tree
Solve T(n) = T(n/4) + T(n/2) + n2:
n2
n2
(n/4)2 (n/2)2 5 n2
16
(n/16)2 (n/8)2 (n/8)2 (n/4)2 25 n 2
256
…
…
Q(1)
n 1
1 x
1 x x 2 ... x n for x ¹ 1
1 x
Example of recursion tree
1 x x 2
...
1
for |x| < 1
1 x
Solve T(n) = T(n/4) + T(n/2) + n2:
n2
n2
(n/4)2 (n/2)2 5 n2
16
(n/16)2 (n/8)2 (n/8)2 (n/4)2 25 n 2
256
…
…
Q(1)
Total = n 1 2
5
16 5 2
16
...
5 3
16
= O(n2) geometric series
The master method