Lab 02
Lab 02
KT&KĐCL/11/BM02E
FACULTY OF INFORMATION TECHNOLOGY
Issue time: 01
ACADEMIC YEAR: 20..... - 20......
CODE: 503040
I. Objective
In this laboratory, students practice solving recurrence relations. A
recurrence relation is the intermediate result generated from counting the number
of basic operations of a recursive algorithm. By solving recurrence relations, we
get a complexity function of the algorithm in its explicit form.
II. Master theorem
a) Formula of Master theorem is stated as follows:
b) Example 1
C (N) = C (2N/3) + 1 2N/3 = N / (3/2)
3
a=1 , b= , f ( N )=1∧f ( n ) ∈Θ ( n ) , therefore k=0
k
2
()
0
k 3
⇒ a=1=b =
2
c) Example 2
T(n) = 2T(n/2) + cn
A = 2, b = 2, k = 1, b k =2=¿ a=b k => T ( n ) ∈ Θ(nlogn)
d) Example 3
C(n) = 2C(n/2) + n – 1
a = 2, b = 2, k = 1, therefore a=b k
According to Master theorem, we have
C ( n ) ∈ Θ ( nk logn )
C ( n ) ∈ Θ ( nlogn )
III. Exercises: Solve the following recurrence relations with Master theorem
a. CN = CN/2 + 1000
b. CN = 3CN/2 + N
c. C (N) = 2C (N/2) + 1
d. CN = 4cN/2 + N
e. C (N) = 9C (N/3) + N
f. C (N) = C (2N/3) + 1
g. C (N) = 3C (N/4) + N2
h. T (n)=T (n/3)+2 T (n/3)+ √ n
2.5
i. T ( n )=T (n/3)+2 T ( n/3)+ n
3
j. T ( n )=T (n/3)+2 T ( n/3)+ n
3
k. T ( n )=T (n/3)+2 T ( n/3)+5
() ()
n n
l. T ( n )=T 3 +2 T 3 +n ×n