Separable form for recurrence relation:
T ( n ) = G ( n , T ( n 1 ) , . . . , T ( n k ) ) \begin{gather*} T(n) = G(n, T(n_1), ..., T(n_k)) \end{gather*} T ( n ) = G ( n , T ( n 1 ) , ... , T ( n k )) where G ( x 0 , x 1 , . . . , x k ) G(x_0, x_1, ..., x_k) G ( x 0 , x 1 , ... , x k ) is a function in k + 1 k+1 k + 1 variables and each n i ( i = 1 , . . . , k ) n_i (i=1,...,k) n i ( i = 1 , ... , k ) is a function of n n n that is strictly less than n n n .
Fibonacci sequence is defined by the recurrence relation:
F ( n ) = F ( n − 1 ) + F ( n − 2 ) \begin{gather*} F(n) = F(n-1) + F(n-2) \end{gather*} F ( n ) = F ( n − 1 ) + F ( n − 2 ) For this, we have k = 2 , n 1 = n − 1 , n 2 = n − 2 k=2, n_1=n-1, n_2=n-2 k = 2 , n 1 = n − 1 , n 2 = n − 2
G ( n , x , y ) = x + y \begin{gather*} G(n, x, y) = x + y \end{gather*} G ( n , x , y ) = x + y Merge sort complexity:
T ( n ) = n + 2 T ( n / 2 ) \begin{gather*} T(n) = n + 2T(n/2) \end{gather*} T ( n ) = n + 2 T ( n /2 ) For this, we have k = 1 , n 1 = n / 2 k=1, n_1=n/2 k = 1 , n 1 = n /2
G ( n , x ) = n + 2 x \begin{gather*} G(n, x) = n + 2x \end{gather*} G ( n , x ) = n + 2 x Rote Method
Related homework questions: h2-Q7
EGVS method
4 stages: E xpand, G uess, V erify and S top-and-Sum.
Example:
T ( n ) = 2 T ( n / 2 ) + n T(n) = 2T(n/2) + n T ( n ) = 2 T ( n /2 ) + n
Expand:
T ( n ) = 2 T ( n / 2 ) + n = 2 ( 2 T ( n / 4 ) + ( n / 2 ) ) + n = 4 T ( n / 4 ) + 2 n = 4 ( 2 T ( n / 8 ) + ( n / 4 ) ) + 2 n = 8 T ( n / 8 ) + 3 n = … \begin{align*} T(n) &= 2T(n/2) + n \\ &= 2 (2 T(n/4) + (n/2)) + n \\ &= 4 T(n/4) + 2n \\ &= 4 (2T(n/8) + (n/4)) + 2n \\ &= 8T(n/8) + 3n \\ &= \dots \end{align*} T ( n ) = 2 T ( n /2 ) + n = 2 ( 2 T ( n /4 ) + ( n /2 )) + n = 4 T ( n /4 ) + 2 n = 4 ( 2 T ( n /8 ) + ( n /4 )) + 2 n = 8 T ( n /8 ) + 3 n = … Guess:
T ( n ) = 2 i T ( n 2 i ) + i n \begin{gather*} T(n) = 2^i T({n\over{2^i}}) + i n \end{gather*} T ( n ) = 2 i T ( 2 i n ) + in Verify: (use natural induction)
Base case: T ( n ) i = 1 = 2 T ( n / 2 ) + n T(n)_{i=1} = 2T(n/2) + n T ( n ) i = 1 = 2 T ( n /2 ) + n holds
Inductive step: Assume T ( n ) i = k T(n)_{i=k} T ( n ) i = k holds, the goal is to prove T ( n ) i = k + 1 T(n)_{i=k+1} T ( n ) i = k + 1 also holds.
T ( n ) = 2 k T ( n 2 k ) + k n = 2 k ( 2 T ( n 2 k + 1 ) + n 2 k ) + k n = 2 k + 1 T ( n / 2 k + 1 ) + ( k + 1 ) n \begin{align*} T(n) &= 2^k T({n\over{2^k}}) + k n \\ &= 2^k (2 T({n\over{2^{k+1}}}) + {n\over{2^k}}) + k n \\ &= 2^{k+1} T(n/2^{k+1}) + (k+1) n \end{align*} T ( n ) = 2 k T ( 2 k n ) + kn = 2 k ( 2 T ( 2 k + 1 n ) + 2 k n ) + kn = 2 k + 1 T ( n / 2 k + 1 ) + ( k + 1 ) n Therefore, this proves T ( n ) i = k + 1 T(n)_{i=k+1} T ( n ) i = k + 1 also holds.
Combining the base case and the inductive step we verified that T ( n ) = 2 i T ( n 2 i ) + i n T(n) = 2^i T({n\over{2^i}}) + i n T ( n ) = 2 i T ( 2 i n ) + in .
Stop:
We can pick i = ⌊ lg n ⌋ i = \lfloor {\lg n} \rfloor i = ⌊ lg n ⌋ for stopping, then 0 < n 2 i ≤ 2 0 < {n\over{2^i}} \le 2 0 < 2 i n ≤ 2 .
By DIC, choose T ( n ) = 0 T(n) = 0 T ( n ) = 0 for all n ≤ 2 n \le 2 n ≤ 2 .
Therefore, for n > 1 n > 1 n > 1 ,
T ( n ) = ⌊ lg n ⌋ n \begin{gather*} T(n) = \lfloor {\lg n} \rfloor n \end{gather*} T ( n ) = ⌊ lg n ⌋ n Basic Sums
Other kinds of sums are often reduces to the following forms.
Arithmetic Sums
S n k : = ∑ i = 1 n i k \begin{gather*} S^k_n := \sum^n_{i=1}{i^k} \end{gather*} S n k := i = 1 ∑ n i k Solution: S n k = Θ ( n k + 1 ) S^k_n = \Theta(n^{k+1}) S n k = Θ ( n k + 1 )
Geometric Sums
When x ≠ 1 x \ne 1 x = 1 ,
S n ( x ) : = ∑ i = 0 n − 1 x i \begin{gather*} S_n(x) := \sum^{n-1}_{i=0}{x^i} \end{gather*} S n ( x ) := i = 0 ∑ n − 1 x i Solution: S ∞ = x n − 1 x − 1 S_\infty = {{x^n - 1}\over{x - 1}} S ∞ = x − 1 x n − 1
Infinite Geometric Series
When ∣ x ∣ < 1 \lvert{x}\rvert < 1 ∣ x ∣ < 1 ,
S ∞ ( x ) : = ∑ i = 0 ∞ x i \begin{gather*} S_{\infty}(x) := \sum^{\infty}_{i=0}{x^i} \end{gather*} S ∞ ( x ) := i = 0 ∑ ∞ x i Solution: S ∞ = 1 1 − x S_{\infty}={1\over{1 - x}} S ∞ = 1 − x 1
Harmonic Series
H n : = 1 + 1 2 + 1 3 + ⋯ + 1 n \begin{gather*} H_n := 1 + {1\over{2}} + {1\over{3}} + \dots + {1\over{n}} \end{gather*} H n := 1 + 2 1 + 3 1 + ⋯ + n 1 Solution: H n = l n ( n ) + g ( n ) H_n = ln(n) + g(n) H n = l n ( n ) + g ( n ) where 0 < g ( n ) < 1 0 < g(n) < 1 0 < g ( n ) < 1 .
Summation Techniques
Growth Types
Related homework questions: h3-Q1
Polynomial Type
A real function f f f is polynomial-type if f f f is non-decreasing (ev.) and there is some C > 1 C > 1 C > 1 such that:
f ( x ) ≤ C f ( x / 2 ) ( e v . ) \begin{gather*} f(x) \le C f(x/2)\ (ev.) \end{gather*} f ( x ) ≤ C f ( x /2 ) ( e v . ) Increasing Exponential Type
f f f increases exponentially if there exists real numbers C > 1 C > 1 C > 1 and k > 0 k > 0 k > 0 such that:
f ( x ) ≥ C f ( x − k ) ( e v . ) \begin{gather*} f(x) \ge C f(x - k)\ (ev.) \end{gather*} f ( x ) ≥ C f ( x − k ) ( e v . ) Decreasing Exponential Type
f f f decreases exponentially if there exists real numbers C > 1 C > 1 C > 1 and k > 0 k > 0 k > 0 such that:
f ( x ) ≤ f ( x − k ) / C ( e v . ) \begin{gather*} f(x) \le f(x - k) / C\ (ev.) \end{gather*} f ( x ) ≤ f ( x − k ) / C ( e v . ) Lemma 8: Closed Properties
(a) Polynomial-type functions are closed under addition, multiplication, and raising to any positive power a > 0 a > 0 a > 0 .
(b) Exponential-type functions f f f are closed under addition, multiplication, and raising to any power a a a . In case a > 0 a > 0 a > 0 , the function f a f^a f a will not change its subtype (increasing or decreasing). In case a < 0 a < 0 a < 0 , the function f a f^a f a will change its subtype.
(c) If f f f is polynomial-type and lg f \lg f lg f is non-decreasing then lg f \lg f lg f is also polynomial-type. If f f f is exponential-type and a > 1 a > 1 a > 1 then so is a f a ^ f a f .
Summation Rules by Growth Type
Related homework questions: h3-Q2
Theorem 6: Summation Rules
S f ( n ) = Θ { n f ( n ) if f is polynomial-type, f ( n ) if f is increasing exponentially, 1 if f is decreasing exponentially. S_f(n) = \Theta \begin{cases} n f(n) & \text{if f is polynomial-type,} \\ f(n) & \text{if f is increasing exponentially,} \\ 1 & \text{if f is decreasing exponentially.} \end{cases} S f ( n ) = Θ ⎩ ⎨ ⎧ n f ( n ) f ( n ) 1 if f is polynomial-type, if f is increasing exponentially, if f is decreasing exponentially. Examples:
Polynomial Sums:
∑ i ≥ 1 n i log ( i ) = Θ ( n 2 log ( n ) ) , ∑ i ≥ 1 n log ( i ) = Θ ( n log ( n ) ) , ∑ i ≥ 1 n i a = Θ ( n a + 1 ) ( a ≥ 0 ) . \sum^n_{i\ge{1}}{i \log(i)} = \Theta(n^2 \log(n)), \sum^n_{i\ge{1}}{\log(i)} = \Theta(n \log(n)), \sum^n_{i\ge{1}}{i^a} = \Theta(n^{a+1})(a\ge{0}). i ≥ 1 ∑ n i log ( i ) = Θ ( n 2 log ( n )) , i ≥ 1 ∑ n log ( i ) = Θ ( n log ( n )) , i ≥ 1 ∑ n i a = Θ ( n a + 1 ) ( a ≥ 0 ) . Exponentially Increasing Sums:
∑ i ≥ 1 n b i = Θ ( b n ) ( b ≥ 0 ) , ∑ i ≥ 1 n i − 5 2 2 i = Θ ( n − 5 2 2 n ) , ∑ i ≥ 1 n i ! = Θ ( n ! ) . \sum^n_{i\ge{1}}{b^i} = \Theta(b^n)(b\ge{0}), \sum^n_{i\ge{1}}{i^{-5}2^{2^i}} = \Theta(n^{-5}2^{2^n}), \sum^n_{i\ge{1}}{i!} = \Theta(n!). i ≥ 1 ∑ n b i = Θ ( b n ) ( b ≥ 0 ) , i ≥ 1 ∑ n i − 5 2 2 i = Θ ( n − 5 2 2 n ) , i ≥ 1 ∑ n i ! = Θ ( n !) . Exponentially Decreasing Sums:
∑ i ≥ 1 n b − i = Θ ( 1 ) ( b ≥ 0 ) , ∑ i ≥ 1 n i 2 i − i = Θ ( 1 ) , ∑ i ≥ 1 n i − i = Θ ( 1 ) . \sum^n_{i\ge{1}}{b^{-i}} = \Theta(1)(b\ge{0}), \sum^n_{i\ge{1}}{i^2 i^{-i}} = \Theta(1), \sum^n_{i\ge{1}}{i^{-i}} = \Theta(1). i ≥ 1 ∑ n b − i = Θ ( 1 ) ( b ≥ 0 ) , i ≥ 1 ∑ n i 2 i − i = Θ ( 1 ) , i ≥ 1 ∑ n i − i = Θ ( 1 ) . Transformation Techniques
Domain Transformation
Related homework questions: h3-Q3 and h3-Q4(combining range transformation)
Example:
Consider:
T ( N ) = T ( N / 2 ) + N \begin{gather*} T(N) = T(N/2) + N \end{gather*} T ( N ) = T ( N /2 ) + N We define t ( n ) : = T ( 2 n ) or N = 2 n t(n) := T(2^n) \text{or} N = 2^n t ( n ) := T ( 2 n ) or N = 2 n .
This transforms the original N-domain into the n-domain:
T ( 2 n ) = T ( 2 n / 2 ) + 2 n T ( 2 n ) = T ( 2 n − 1 ) + 2 n t ( n ) = t ( n − 1 ) + 2 n \begin{align*} T(2^n) &= T(2^n/2) + 2^n \\ T(2^n) &= T(2^{n-1}) + 2^n \\ t(n) &= t(n-1) + 2^n \end{align*} T ( 2 n ) T ( 2 n ) t ( n ) = T ( 2 n /2 ) + 2 n = T ( 2 n − 1 ) + 2 n = t ( n − 1 ) + 2 n We get this standard form. By DIC, we choose the boundary condition t ( n ) = 0 t(n) = 0 t ( n ) = 0 for all n ≤ 0 n \le 0 n ≤ 0 .
We get sum:
t ( n ) = ∑ i ≥ 0 n 2 n = Θ ( 2 n ) \begin{gather*} t(n) = \sum^n_{i\ge{0}}{2^n}=\Theta(2^n) \end{gather*} t ( n ) = i ≥ 0 ∑ n 2 n = Θ ( 2 n ) Because we have n = lg N n = \lg N n = lg N ,
T ( N ) = Θ ( N ) \begin{gather*} T(N) = \Theta(N) \end{gather*} T ( N ) = Θ ( N ) On Lecture II Page 46, L1120, we get the exact sum by transforming the descending sum to the ascending sum.
Range Transformation
Related homework questions: h3-Q4(combining domain transformation)
Example:
T ( n ) = 2 T ( n − 1 ) + n \begin{gather*} T(n) = 2T(n-1) + n \end{gather*} T ( n ) = 2 T ( n − 1 ) + n We define t ( n ) : = T ( n ) 2 n t(n) := {T(n)\over{2^n}} t ( n ) := 2 n T ( n ) , then divide the both sides of the original equation by 2 n 2^n 2 n .
T ( n ) 2 n = 2 T ( n − 1 ) 2 n + n 2 n T ( n ) 2 n = T ( n − 1 ) 2 n − 1 + n 2 n t ( n ) = t ( n − 1 ) + n 2 n \begin{align*} {T(n)\over{2^n}} &= 2{T(n-1)\over{2^n}} + {n\over{2^n}} \\ {T(n)\over{2^n}} &= {T(n-1)\over{2^{n-1}}} + {n\over{2^n}} \\ t(n) &= t(n-1) + {n\over{2^n}} \end{align*} 2 n T ( n ) 2 n T ( n ) t ( n ) = 2 2 n T ( n − 1 ) + 2 n n = 2 n − 1 T ( n − 1 ) + 2 n n = t ( n − 1 ) + 2 n n We get this standard form. By DIC, we choose the boundary condition t ( n ) = 0 t(n) = 0 t ( n ) = 0 for all n ≤ 0 n \le 0 n ≤ 0 .
We get sum: (∑ i ≥ 0 n n 2 n \sum^n_{i\ge{0}}{n\over{2^n}} ∑ i ≥ 0 n 2 n n is exponentially decreasing)
t ( n ) = ∑ i ≥ 0 n n 2 n = Θ ( 1 ) \begin{gather*} t(n) = \sum^n_{i\ge{0}}{n\over{2^n}}=\Theta(1) \end{gather*} t ( n ) = i ≥ 0 ∑ n 2 n n = Θ ( 1 ) Because t ( n ) = T ( n ) 2 n t(n) = {T(n)\over{2^n}} t ( n ) = 2 n T ( n ) ,
T ( n ) = Θ ( 2 n ) \begin{gather*} T(n) = \Theta(2^n) \end{gather*} T ( n ) = Θ ( 2 n ) Master Theorem
Related homework questions: h2-Q8
Master recurrence:
T ( n ) = a T ( n / b ) + d ( n ) \begin{gather*} T(n) = a T(n/b) + d(n) \end{gather*} T ( n ) = a T ( n / b ) + d ( n ) where a > 0 a > 0 a > 0 , b > 0 b > 0 b > 0 are real constants and d ( n ) d(n) d ( n ) the driving/forcing function.
Watershed constant
w = log b ( a ) w = \log_b(a) w = log b ( a )
Watershed function
W ( n ) = n w = n log b ( a ) W(n) = n^w = n^{\log_b(a)} W ( n ) = n w = n l o g b ( a )
Useful link: Online basic master theorem solver
Master Theorem
Theorem 10: Master Theorem on Lecture II Page 51, L1207
T ( n ) = Θ { n w , if d ( n ) = O ( n w − ϵ ) for some ϵ > 0 , C A S E ( − ) n w log ( n ) , if d ( n ) = Θ ( n w ) , C A S E ( 0 ) d ( n ) , if a ⋅ d ( n / b ) ≤ c ⋅ d ( n ) for some 0 < c < 1. C A S E ( + ) \begin{gather*} T(n) = \Theta \begin{cases} n^w, & \text{if } d(n) = O(n^{w-\epsilon}) \text{ for some } \epsilon > 0, & CASE(-) \\ n^w \log(n), & \text{if } d(n) = \Theta(n^w), & CASE(0) \\ d(n), & \text{if } a\cdot d(n/b) \le c\cdot d(n) \text{ for some } 0 < c < 1. & CASE(+) \\ \end{cases} \end{gather*} T ( n ) = Θ ⎩ ⎨ ⎧ n w , n w log ( n ) , d ( n ) , if d ( n ) = O ( n w − ϵ ) for some ϵ > 0 , if d ( n ) = Θ ( n w ) , if a ⋅ d ( n / b ) ≤ c ⋅ d ( n ) for some 0 < c < 1. C A SE ( − ) C A SE ( 0 ) C A SE ( + ) Extended Master Theorem
Theorem 12: Extended Master Theorem on Lecture II Page 54, L1282
T ( n ) = Θ { d ( n ) , if a ⋅ d ( n / b ) ≤ c ⋅ d ( n ) for some 0 < c < 1. C A S E ( + ) W ( n ) log log n , if d ( n ) = Θ ( W ( n ) log c ( n ) ) for c = − 1 , C A S E ( 1 ) W ( n ) log c + 1 ( n ) , if d ( n ) = Θ ( W ( n ) log c ( n ) ) for c > − 1 , C A S E ( 0 ) W ( n ) , if d ( n ) = O ( W ( n ) log c ( n ) ) for c < − 1. C A S E ( − ) \begin{gather*} T(n) = \Theta \begin{cases} d(n), & \text{if } a\cdot d(n/b) \le c\cdot d(n) \text{ for some } 0 < c < 1. & CASE(+) \\ W(n)\log\log n, & \text{if } d(n) = \Theta(W(n)\log^c(n)) \text{ for } c = -1, & CASE(1) \\ W(n)\log^{c+1}(n), & \text{if } d(n) = \Theta(W(n)\log^c(n)) \text{ for } c > -1, & CASE(0) \\ W(n), & \text{if } d(n) = O(W(n)\log^c(n)) \text{ for } c < -1. & CASE(-) \\ \end{cases} \end{gather*} T ( n ) = Θ ⎩ ⎨ ⎧ d ( n ) , W ( n ) log log n , W ( n ) log c + 1 ( n ) , W ( n ) , if a ⋅ d ( n / b ) ≤ c ⋅ d ( n ) for some 0 < c < 1. if d ( n ) = Θ ( W ( n ) log c ( n )) for c = − 1 , if d ( n ) = Θ ( W ( n ) log c ( n )) for c > − 1 , if d ( n ) = O ( W ( n ) log c ( n )) for c < − 1. C A SE ( + ) C A SE ( 1 ) C A SE ( 0 ) C A SE ( − ) Multi-term Master Recurrences
Related homework questions: h3-Q5
T ( n ) = d ( n ) + ∑ i = 1 k a i T ( n / b i ) \begin{gather*} T(n) = d(n) + \sum_{i=1}^{k}{a_i T(n/b_i)} \end{gather*} T ( n ) = d ( n ) + i = 1 ∑ k a i T ( n / b i ) where a i > 0 a_i > 0 a i > 0 and b 1 > b 2 > ⋯ > b k > 1 b_1 > b_2 > \cdots > b_k > 1 b 1 > b 2 > ⋯ > b k > 1 are real constants.
Watershed constant
It is the real number α \alpha α such that:
1 = ∑ i = 1 k a i b i α \begin{align*} 1 = \sum_{i=1}^{k}{a_i\over{b_i^{\alpha}}} \end{align*} 1 = i = 1 ∑ k b i α a i It clearly exists and is unique.
Multi-term Master Theorem
Theorem 15: Multi-term Master Theorem on Lecture II Page 62, L1483
T ( n ) = Θ { n α , if d ( n ) = O ( n w − ϵ ) for some ϵ > 0 , C A S E ( − ) n w , if d ( n ) = Θ ( n w ) , C A S E ( 0 ) d ( n ) , if ∑ i = 1 k a i ⋅ d ( n / b i ) ≤ c ⋅ d ( n ) , C A S E ( + ) \begin{gather*} T(n) = \Theta \begin{cases} n^{\alpha}, & \text{if } d(n) = O(n^{w-\epsilon}) \text{ for some } \epsilon > 0, & CASE(-) \\ n^w, & \text{if } d(n) = \Theta(n^w), & CASE(0) \\ d(n), & \text{if } \sum^k_{i=1}{a_i\cdot d(n/{b_i})} \le c\cdot d(n), & CASE(+) \\ \end{cases} \end{gather*} T ( n ) = Θ ⎩ ⎨ ⎧ n α , n w , d ( n ) , if d ( n ) = O ( n w − ϵ ) for some ϵ > 0 , if d ( n ) = Θ ( n w ) , if ∑ i = 1 k a i ⋅ d ( n / b i ) ≤ c ⋅ d ( n ) , C A SE ( − ) C A SE ( 0 ) C A SE ( + ) Real Induction
Related homework questions: h2-Q9