Lecture3 1
Lecture3 1
Cormen (4.3-4.6)
Levetin (2.4-2.5)
Fibonacci Sequences
(Natural Models)
Fibonacci Sequence
• By studying Fibonacci numbers and constructing
Fibonacci sequence we can imagine how
mathematics is connected to apparently unrelated
things in this universe.
• Even though these numbers were introduced in
1202 in Fibonacci’s book Liber abaci, but these
numbers and sequence are still fascinating and
mysterious to people of today.
• Fibonacci, gave a problem in his book whose
solution was the Fibonacci sequence as we will
discuss it today.
Fibonacci’s Problem
Statement:
• Start with a pair of rabbits, one male and one female,
born on January 1.
• Assume that all months are of equal length and that
rabbits begin to produce two months after their own
birth.
• After reaching age of two months, each pair produces
another mixed pair, one male and one female, and then
another mixed pair each month, and no rabbit dies.
How many pairs of rabbits will there be after one year?
F1 = 1 end of month 1
end of month 2
F2 = 1
end of month 3
F3 = 2
F4 = 3
end of month 4
end of month 5
F5 = 5
end of month 6
F6 = 8
end of month 7
F7 = 13 end of month 12
... ... ...
Construction of Mathematical Model
• Total pairs at level k = Total pairs at level k-1 + Total
pairs born at level k (1)
• Since
Total pairs born at level k = Total pairs at level k-2 (2)
• Hence by equation (1) and (2)
Total pairs at level k = Total pairs at level k-1 + Total
pairs at level k-2
• Now let us denote
Fk = Total pairs at level k
• Now our recursive mathematical model will become
Fk = Fk-1 + Fk-2
Computing Values using Mathematical Model
Since Fk = Fk-1 + Fk-2 F0 = 0, F1= 1
• F 2 = F 1 + F 0= 1 + 0 = 1
• F 3 = F 2 + F 1= 1 + 1 = 2
• F 4 = F 3 + F 2= 2 + 1 = 3
• F 5 = F 4 + F 3= 3 + 2 = 5
• F 6 = F 5 + F 4= 5 + 3 = 8
• F7 = F6 + F5= 8 + 5 = 13
• F8 = F7 + F6= 13 + 8 = 21
• F9 = F8 + F7= 21 + 13 = 34
• F10 = F9 + F8= 34 + 21 = 55
• F11 = F10 + F9= 55 + 34 = 89
• F12 = F11 + F10= 89 + 55 = 144 . . .
Explicit Formula Computing
Theorem: Fibonacci Numbers
The fibonacci sequence F0,F1, F2,…. Satisfies
the recurrence relation
Fk Fk 1 Fk 2 k 2
with initial condition F0 F1 1
1 5 1 5
Let
and then
2 2
1 n 1 n
Fn
5 5
Verification of the Explicit
Example: Compute F Formula 3
1 n 1 n 1 5 1 5
Since Fn where
and then
2
5 5 2
3 3
1 1 5 1 1 5
F3
5 2 5 2
F3
1
8. 5
1 3.1. 5 3.1.5 5 5 1
8. 5
1 3.1. 5 3.1.5 5 5
F3
1
8. 5
1 3.1. 5 3.1.5 5 5 1 3.1. 5 3.1.5 5 5 2
Recursive Algorithm Computing Fibonacci Numbers
Fibo-R(n)
if n = 0
then 0
Terminating conditions
if n = 1
then 1
else Fibo-R(n-1) + Fibo-R(n-2) Recursive calls
Running Time of Recursive Fibonacci Algorithm
• Least Cost: To find an asymptotic bound of computational
cost of this algorithm, we can use a simple trick to solve this
recurrence containing big oh expressions
• Simply drop the big O from the recurrence, solve the
recurrence, and put the O back. Our recurrence
O (1) if n 2
T (n)
T (n 1) T (n 2) n 2
will be refined to
1 if n 2
T (n)
T (n 1) T (n 2) n 2
Running Time of Recursive Fibonacci Algorithm
1 n 1 n 1 5 1 5
Fn
where
and (2)
5 5 2 2
x y y
1.62
y x
1 5
1.62
2
x 1 0.62,
1
y 1
of course x y and
xy y 1 1
i.e.
y x 1 1
2
1 0
Drawback in Recursive Algorithms
Recursion Tree
F(n)
F(n-1) F(n-2)
F0 = 0
F1 = 1
F2 = 1
F3 = 3
F4 = 5
F5 = 11
F6 = 21
Construction of Mathematical Model
• Total pairs at level k =
Total pairs at level k-1 + Total pairs born at level k (1)
• Since
Total pairs born at level k =
2 x Total pairs at level k-2
(2)
• By (1) and (2), Total pairs at level k =
Total pairs at level k-1 + 2 x Total pairs at level k-2
• Now let us denote
Fk = Total pairs at level k
• Our recursive mathematical model:
Fk = Fk-1 + 2.Fk-2
• General Model (m pairs production): Fk = Fk-1 + m.Fk-2
Generalization
• Recursive mathematical model
(one pair production)
Fk = Fk-1 + Fk-2
• Recursive mathematical model
(two pairs production)
Fk = Fk-1 + 2.Fk-2
• Recursive mathematical model
(m pairs production)
Fk = Fk-1 + m.Fk-2
Computing Values using Mathematical Model
Since Fk = Fk-1 + 2.Fk-2 F0 = 0, F1 = 1
• F2 = F1 + 2.F0= 1 + 0 = 1
• F3 = F2 + 2.F1= 1 + 2 = 3
• F4 = F3 + 2.F2= 3 + 2 = 5
• F5 = F4 + 2.F3= 5 + 6 = 11
• F6 = F5 + F4= 11 + 10 = 21
• F7 = F6 + F5= 21 + 22 = 43
• F8 = F7 + F6= 43 + 42 = 85
• F9 = F8 + F7= 85 + 86 = 171
• F10 = F9 + F8= 171 + 170 = 341
• F11 = F10 + F9= 341 + 342 = 683
• F12 = F11 + F10= 683 + 682 = 1365 . . .
Another Generalization of Rabbits Problem
Statement:
• Start with a different kind of pair of rabbits, one male and
one female, born on January 1.
• Assume all months are of equal length and that rabbits
begin to produce three months after their own birth.
• After reaching age of three months, each pair produces
another mixed pairs, one male and other female, and then
another mixed pair each month, and no rabbit dies.
How many pairs of rabbits will there be after one year?
F1 = 1
F2 = 1
F3 = 1
F4 = 2
F5 = 3
F6 = 4
F7 = 6
F8 = 9
F9 = 13
F10 = 19
Construction of Mathematical Model
• Total pairs at level k =
Total pairs at level k-1 + Total pairs born at level k (1)
• Since
Total pairs born at level k = Total pairs at level k-3 (2)
• By (1) and (2)
Total pairs at level k =
Total pairs at level k-1 + Total pairs at level k-3
• Now let us denote
Fk = Total pairs at level k
• This time mathematical model: Fk = Fk-1 + Fk-3
Computing Values using Mathematical Model
Since Fk = Fk-1 + Fk-3 F0 = 0, F1= F2= 1
• F 3 = F 2 + F 0= 1 + 0 = 1
• F 4 = F 3 + F 1= 1 + 1 = 2
• F 5 = F 4 + F 2= 2 + 1 = 3
• F 6 = F 5 + F 3= 3 + 1 = 4
• F 7 = F 6 + F 4= 4 + 2 = 6
• F 8 = F 7 + F 5= 6 + 3 = 9
• F9 = F8 + F6= 9 + 4 = 13
• F10 = F9 + F7= 13 + 6 = 19
• F11 = F10 + F8= 19 + 9 = 28
• F12 = F11 + F9= 28 + 13 = 41 . . .
More Generalization
• Recursive mathematical model
(one pair, production after three months)
Fk = Fk-1 + Fk-3
• Recursive mathematical model
(two pairs, production after three months)
Fk = Fk-1 + 2.Fk-3
• Recursive mathematical model
(m pairs, production after three months)
Fk = Fk-1 + m.Fk-3
• Recursive mathematical model
(m pairs, production after n months)
Fk = Fk-1 + m.Fk-n
Applications of Fibonacci Sequences and Golden
Ratio
Fibonacci sequences
• Are used in trend analysis
• By some pseudorandom number generators
• The number of petals is a Fibonacci number.
• Many plants show the Fibonacci numbers in the
arrangements of the leaves around the stems.
• Seen in arrangement of seeds on flower heads
• Consecutive Fibonacci numbers give worst case
behavior when used as inputs in Euclid’s algorithm.
• As n approaches infinity, the ratio F(n+1)/F(n)
approaches the golden ratio:
=1.6180339887498948482...
Applications of Fibonacci Sequences
Fibonacci sequences
• The Greeks felt that rectangles whose sides are in
the golden ratio are most pleasing
• Sum of the first n Fibonacci numbers is F(n+2)-1.
• The shallow diagonals of Pascal’s triangle sum to
Fibonacci numbers.
• Except n = 4, if F(n) is prime, then n is prime.
• Equivalently, if n not prime, then F(n) is not prime.
• gcd( F(n), F(m) ) = F( gcd(n, m) )
Pascal’s Triangle
Euclid’s algorithm
• The Euclidean Algorithm for finding GCD(A,B) is as
follows:
• If A = 0 then GCD(A,B)=B, since the GCD(0,B)=B, and
we can stop.
• If B = 0 then GCD(A,B)=A, since the GCD(A,0)=A, and
we can stop.
• Write A in quotient remainder form (A = B⋅Q + R)
• Find GCD(B,R) using the Euclidean Algorithm since
GCD(A,B) = GCD(B,R)
Example
• Find the GCD of 270 and 192
• A=270, B=192A ≠0B ≠0
• Use long division to find that 270/192 = 1 with a
remainder of 78.
• We can write this as: 270 = 192 * 1 +78
• Find GCD(192,78), since GCD(270,192)=GCD(192,78)
A=192, B=78 A ≠0 B ≠0 Use long division to find that
192/78 = 2 with a remainder of 36.
• We can write this as:192 = 78 * 2 + 36
• Find GCD(78,36), since GCD(192,78)=GCD(78,36)
A=78, B=36 A ≠0 B ≠0 Use long division to find that
78/36 = 2 with a remainder of 6.
• We can write this as:78 = 36 * 2 + 6
• Find GCD(36,6), since GCD(78,36)=GCD(36,6) A=36,
B=6
• And so on……
Golden Ratio
Golden Ratio
Golden Ratio
Golden Ratio
What is Recursion?
• More concisely, a recursive function or definition
is defined in terms of itself.
• Recursion is a computer algorithm that calls itself
in a steps having a termination condition.
• The successive repetitions are processed up to
the critical step where the condition is met.
• In recursive algorithms, each repetition is
processed from the last one called to the first.
• Recursion is a wonderful technique for dealing
with many problems where problems and sub-
problems have same mechanism to solve it.
Merits and Demerits of Recursion
• Recursive solutions are much easier to conceive of
and code than their iterative counterparts.
• Every problem is not solvable using this approach
What kinds of problems are solved with recursion?
• Generally, problems which are defined in terms of
themselves are usually good candidates for
recursive techniques.
Example
• Finding factorial of a number is an easiest example
one can think using recursion
Recursive Mathematical Model
• Since n! can be computed as: 5! = 5*4*3*2*1.
• If we have a close look at this, we notice that
5! = 5*4!.
• Now if denote F(n) = n! then it can be written as
F(n) = n.F(n-1)
• Assume 0! = 1 i.e. F(0) = 1, and solve till termination
F(n) = n.F(n-1) = n.(n-1).F(n-2) = n.(n-1).(n-2).F(n-3)
...
F(n) = n.(n-1).(n-2). . . 2.1.F(0) = n.(n-1).(n-2). . . 2.1.1
1 if n 0
F (n)
n.F (n 1) otherwise
Methods for solving Recurrence
(1) if n 1
T (n) n n
T 2 T 2 (n) otherwise
Assumption in Solving Recurrence Relation
• We do not give any explicit value for small n
Because changing n, T (1) changes solution to
recurrence. Solution typically doesn’t change by more
than a constant factor, so order of growth is unchanged
• Solve recurrences, often omit floors, ceilings, etc.
• First analyze without these details and later determine
whether such assumptions matter or not.
• Usually it dose not matter but it is important to know
when it does and when it does not
(1) if n 1
T (n) n
2.T ( 2 ) (n) otherwise
Methods Solving Recurrence Relation
Proof
let us suppose that
b c
log s a log t
b
s t
a b and b c
Now b t c, ( a s ) t c
st
a c, log ca s t
s t logca , log ba log bc log ca proved
Some Important Rules used in this Section
log n4 log 34
Prove that 3 n
Proof
log n4 log 34
3 n
logn4 log34
log 3 (3 ) log 3 (n )
n 3 3 n
log log log log
4 3 4 3
n 3 n
log log log
4 4 3
n n
log log 4 4
b
log log log
a
c
b
c
a
0 n 0
s (n)
c s (n 1) n 0
• s(n) =
c + s(n-1)
c + c + s(n-2)
2c + s(n-2)
2c + c + s(n-3)
3c + s(n-3)
…
kc + s(n-k) = ck + s(n-k)
0 n 0
s (n)
c s (n 1) n 0
• So far for n >= k we have
– s(n) = ck + s(n-k)
• What if k = n?
– s(n) = cn + s(0) = cn
0 n 0
s (n)
c s (n 1) n 0
• So far for n >= k we have
– s(n) = ck + s(n-k)
• What if k = n?
– s(n) = cn + s(0) = cn
• So 0 n 0
s (n)
c s (n 1) n 0
• Thus in general
– s(n) = cn
0 n 0
s (n)
n s (n 1) n 0
• s(n)
= n + s(n-1)
= n + n-1 + s(n-2)
= n + n-1 + n-2 + s(n-3)
= n + n-1 + n-2 + n-3 + s(n-4)
=…
= n + n-1 + n-2 + n-3 + … + n-(k-1) + s(n-k)
0 n 0
s (n)
n s (n 1) n 0
• s(n)
= n + s(n-1)
= n + n-1 + s(n-2)
= n + n-1 + n-2 + s(n-3)
= n + n-1 + n-2 + n-3 + s(n-4)
=…
= n + n-1 + n-2 + n-3 + … + n-(k-1) + s(n-k)
n
i
=i n k 1
s (n k )
0 n 0
s (n)
n s (n 1) n 0
• So far for n >= k we have
n
i
i n k 1
s (n k )
0 n 0
s (n)
n s (n 1) n 0
• So far for n >= k we have
n
i
i n k 1
s (n k )
• What if k = n?
0 n 0
s (n)
n s (n 1) n 0
• So far for n >= k we have
n
i
i n k 1
s (n k )
• What if k = n?
n
n 1
n
i 1
i s (0) i 0 n
i 1 2
0 n 0
s (n)
n s (n 1) n 0
• So far for n >= k we have
n
i
i n k 1
s (n k )
• What if k = n?
n
n 1
n
i 1
i s (0) i 0 n
i 1 2
• Thus in general
n 1
s ( n) n
2
The Substitution Method
Solve the recurrence relation given below.
1 if n 1
T ( n) n
3 T ( 4 ) n otherwise
Solution:
n
(1) T (n) 3 T ( ) n
4
replace the value of n by n 4 in (1)
n n n
(2) T ( ) 3 T ( 2 )
4 4 4
The Substitution Method
n n n
(3) T ( 2 ) 3 T ( 3 ) 2 and so on
4 4 4
n n n
(4) T ( k1
) 3 T ( )
4 4k 4k 1
n
Now substitute the value of T ( ) from (2) to (1)
4
n n
(5) T (n) 3 3T ( 2 ) n
4 4
n 3
3 2 T ( 2 ) ( ) n n
4 4
n
substitute the value of T ( 2
) from (3) to (5) equation, we have
4
2n n 3
T ( n) 3 3 T ( 3 ) 2 ( ) n n
4 4 4
The Substitution Method
log n
4 n 3 3 4n 3 3
k 4
4 k n, k log n4
The Substitution Method
logn4
T (n) 4n 3 3
log34
T (n) 4n 3 n
T (n) 4n 3 n 0 1
T (n) 4n 3 n
k
Let us suppose that, n b
k a a k1
T (n) a T (1) n 1 ( ) .... ( )
b b
A Hard Example
a k
1 ( ) k
b k b a
a T (1) n( )(1 k )
k
a T (1) n
1 a b a b
b
k k
k b b a
a 1 n( )( k
)
b a b
k k
b b a k
k
a n( )( ) n b
b a n
A Hard Example
k b k k
a ( )(b a )
b a
k b k b k
a b a
b a b a
b k b a b k
b ( )a
b a b a
A Hard Example
b k a logbn
T ( n ) ( ) b a
b a b a
b k a logba let logba
b n
b a b a
a b log 1 0 1
a
b
b a
T ( n) n n T (n) (n)
b a b a
More Hard Example using Substitution
Method
Solve the recurrence relation given below.
1 if n 1
T ( n) n 2
3 T ( 4 ) cn otherwise
Solution:
n 2
(1) T (n) 3 T ( ) cn
4
n n n 2
(2) T ( ) 3 T ( 2 ) c( )
4 4 4
Contd..
n n n 2
(3) T ( 2 ) 3 T ( 3 ) c( 2 )
4 4 4
n n n 2
(4) T ( 3 ) 3 T ( 4 ) c( 3 )
4 4 4
and so on
n n n 2
(5) T ( k 1 ) 3 T ( k ) c( k 1 )
4 4 4
Contd..
n
Now substitute the value of T ( ) from (2) to (1)
4
n n 2
(6) T (n) 3 3T ( 2 ) c( ) cn 2
4 4
2 n n 2 2
3 T ( 2 ) 3c( ) cn
4 4
n
substitute the value of T ( 2 ) from (3) to (6), we have
4
n n 2 n 2
T ( n) 3 3T ( 3 ) c ( 2 ) 3c ( ) cn 2
2
4 4 4
Contd..
3 n 2 n 2 n 2 2
3 T ( 3 ) 3 c( 2 ) 3c ( ) cn
4 4 4
3 n 3 2 2 3 1 2 2
3 T ( 3 ) ( 2 ) cn ( 2 ) cn cn
4 4 4
k n 3 k1 3 k 2 3 0 2
T (n) 3 T ( k ) ( 2 ) ( 2 ) ( 2 ) cn
4 4 4 4
Contd..
k
Let us suppose that n can be expressed as n 4
k 2 3 3 2 3 k1
T (n) 3 T (1) cn 1 ( ) ( )
16 16 16
3 k
1 ( )
T (n) 3 k 1 cn 2 ( 16 )
1 3
16
k
16 3
3 k cn 2 (1 k )
13 16
Contd..
k 2 2
since 4 n (4 ) n
k
k 2
(4 ) n 2 k 2
16 n
k
k16 3 2
T (n) 3 cn (1 k )
13 16
16 n 2
3 k
16
k 2 k
3 k cn 2 ( 2
) 3 c (n 3 )
13 n 13
16 2 16 k
c n (1 c)3
13 13
Contd..
16 2 16 log n
T (n) cn (1 c)3 4
13 13
16 2 16 log 3
cn (1 c)n 4
13 13
let log34 where 0 1
16 2 16
T (n) cn (1 c)n
13 13
Hence T (n) (n ) 2
Observations
1 if n 1
T (n) n k
a T ( ) cn otherwise
b
k1
k
en fn log a
b suppose b a
k
k log b 1
en fn b
k k1 . log b k k1
en f .n b en f .n
max( k , k1 )
(n )
Recursion Tree Method
Recursion Tree Method
• Although substitution method can provide a
sufficient proof that a solution to a recurrence is
correct, sometimes difficult to give a good guess.
• Drawing out a recursion tree, is a straight forward
way to devise a good guess.
• In recursion tree, nodes represent costs of a sub-
problems in the set of recursive function
invocations.
• We sum costs within each level of the tree to obtain
a set of per-level costs.
• And then we sum all per-level costs to determine
the total cost of all levels of the recursion.
• Recursion trees are particularly useful when
recurrence describes running time of divide and
conquer algos.
Recursion Tree Method
• Recursion tree is best one used to generate a good
guess, which is then verified by substitution method
• When using a recursion tree to generate a good
guess, we can often tolerate a small amount of
sloppiness since we have to verify it later on.
• If we are careful when drawing out a recursion tree
and summing costs, then we can use a recursion
tree as a direct proof of a solution to any
recurrence of any problem.
• Here, we will use recursion trees directly to prove
theorem that forms the basis of the master method.
Recursion Tree
1 if n 1
T (n)
n
3.T ( ) cn 2 if otherwise
4
Assumption: We assume that n is exact power of 4.
The recurrence tree is given in the next slide
Recursion Tree Method
c.n2
T(n) = 3.T(n/4)+c.n2
c.n2
c.n2 c.n2
Suppose n=4k
2
c(n/16)2 c(n/16)2 c(n/16)2 c(n/16)2 c(n/16)2 c(n/16)2 c(n/16)2 c(n/16)2 c(n/16)
(3/16)2.c.n2
2 2 2
c(n/16)2 c(n/16)2 c(n/16) c(n/16)2 c(n/16)2 c(n/16) c(n/16) c(n/16) c(n/16)
2 2
(3/16)2.c.n2
(3/42)k-1 cn2
T(n/4k) T(n/4k) T(n/4k) T(n/4k) T(n/4k) T(n/4k) T(n/4k) T(n/4k)
T(1) T(1) T(1) T(1) T(1) T(1) T(1) T(1) T(1) T(1) T(1) T(1) (nlog43)
Recursion Tree Method
• Now the total computation cost would be
= Cost of Childs + Cost of tree excluding childes
= Cost of Child x total number of Childs + Cost of
all levels excluding childes level
= total number of Childs + sum of costs at each
level excluding childes level.
logn4
T (n) 3 cost at Levels above child level
log3 4 3 0 3 1 3 k1 2
T (n) (n ) ( 2 ) ( 2 ) ( 2 ) cn
4 4 4
Recursion Tree Method
Now total computational cost can be calculated as
log3 4 3 0 3 1 3 k1 2
T (n) (n ) ( 2 ) ( 2 ) ( 2 ) cn
4 4 4
Where 4 k n k log 4 n
log3 4 3 0 3 1 2
T (n) (n ) ( 2 ) ( 2 ) cn
4 4
log3 4 1 2 log3 4 16 2
T (n) (n )( )cn (n ) cn
3 13
1 ( )
16
Hence T (n) (n 2 )
Practice Problems
applies:
T (n) n log a
b
when f (n) On
log a
b
(1) if n 1
T (n) n
a.T ( ) f (n) if n b i
b
where i is a positive integer. Then
logb n 1
logb a n
T (n) (n )
j 0
j
a .f ( j )
b
Master Theorem
Lemma 2: Let a 1, b > 1 be constants, let f(n) be a
non-negative function defined on exact power of b. A
function g(n) defined over exact powers of b by
logb n 1
n
g ( n) j 0
j
a .f ( j )
b
logb a
1. If f (n) (n logb a
), for some constants 0, then g (n) (n )
a a
2. If f (n) (n log ), then g (n) (n log . lg n )
b b
logb n 1
n
We are given that: g ( n)
j 0
j
a .f ( j )
b
(2)
a
• Consider j
a .( j ) n logb
. ( ) j
lo gb a
j 0 b j 0 b
a
• Assume that:
logb a
x
b
• Taking log on both sides: log ( a ) log x
b lo g a b b
b
lo gb a
a b a a b
log b log b log b x log b log b . log b log b x
a a
log b log b log b x 0 log b x x 1
Master Theorem
n n logb n 1
logb 1
n logb logb 1
a.b
j
a .( j )
a
n logb a
. ( lo gb a
) n
j logb a
. )
(b j
j 0 b j 0 b j 0
logb a 0 1 logb n 1
n .((b ) (b ) ... (b ) )
• It is a geometric series with first term 1,
common ratio b and number of terms as logbn.
logb n
Hence .g(n), . logb b
a (b ) 1 a b logb n
1 logb a n 1
n logb
(
) n logb
( ) n ( )
b 1 b 1 b 1
a n 1 logb a logb a logb a
n logb ( ) c.n c.n (n )
b 1
Hence
Master Theorem
logb a
Case 2: f (n) (n )
n n logb a
Which implies that: f ( j ) (( j ) ) (3)
b b
logb n 1
We are given that: g ( n) n
j 0
j
a .f ( j )
b
(4)
a
We have already proved that logb a
1
b
logb n 1
logb a
g (n) (n logb a
. 1) (n . (1 1 ... 1 )
j 0
logb n number of terms
logb a n
(n . log b ) case is proved
Master Theorem
Case 3: n n c
Given that: a. f ( ) c. f (n) f ( ) . f (n)
b b a
n c n c 2 n c 2
f ( 2 ) . f ( ) ( ) . f (n) f ( 2 ) ( ) . f (n)
b a b a b a
n c 2 n c 3 n c 3
f ( 3 ) ( ) . f ( ) ( ) . f (n) f ( 3 ) ( ) . f (n)
b a b a b a
In general: f ( n ) ( c ) j . f (n)
bj a
Equivalently: a j . f ( n ) c j . f (n)
bj
Master Theorem
logb n 1
n
We are given that: g (n)
j 0
j
a .f ( j )
b
(5)
n
We have proved that: a . f ( j ) c j . f (n)
j
(6) b
From equation (5) and (6)
logb n 1 logb n 1
n
g ( n)
j 0
j
a .f ( j )
b c . f ( nj
) c . f (n)
j
j 0 j 0
1
g (n) f (n)( ) ( f (n))
1 c
(7)
Master Theorem
Since f(n) appears in definition of g(n) and all
terms of g(n) are non-negative, we can conclude
easily that
logb a logb a
2. If f (n) (n ), then T (n) (n . lg n )
3. If f (n) (n log )
b
a
for some > 0, and a.f(n/b) ≤ c.f(n) for
some constant c < 1and sufficiently large n, then T(n) =
(f(n))
Master Theorem
Proof: Case 1
Given that
(1) if n 1
T (n) n
a.T ( ) f (n) if n b i
b
logb n 1
logb a n
By Lemma 4.2: T (n) (n )
j 0
j
a .f ( j )
b
Hence
T (n) ( f (n))
This proves the Lemma 3