1.
Sol1
Part 1
Sort the set S of n integers with θ(nlg n) sorting algorithm. For example, the merge
sort or the heap sort.
Part2
For each integer (assumed i) in the set S, we try to check whether the integer (x-i)
exists in the remaining elements of S or not by binary search. Because the time
complexity of binary search is θ(lg n), the time complexity of part2 is θ(nlg n).
Therefore, the total time complexity is θ(nlg n)
Sol2
Path1 : Sort the set S of n integers with θ(nlg n) sorting algorithm. =>O(NlogN)
Path2 : Let all elements in the set S minus X ,then be the set S’
=>O(N)
Path3 : Use merge sort to check S and S’, if they have more than tow repeat number ,
then S exist tow elements which sum is X.
=>O(N)
EX :
S = {4,9,4,7,6,8} X =14
Path1 : S={4,4,6,7,8,9}
Path2 : S’={10,10,8,7,6,5}
Path3: {6,6} and {7,7}and{8,8} => S exist tow elements which sum is X.
2.
The statement means T(A)≥f(n) , which 0≤f(n)≤Cn lgn . It doesn’t tell us anything.
T(A) might be n2, 2n, n!, …
3.
Disprove
f(n) = O(g(n)) implies g(n) = O(f(n))
f(n) = O(g(n)) → f(n) ≤ C1 g(n)
--(i)
& g(n) = O(f(n)) → g(n) ≤ C2 f(n) which is not true when (i) holds true.
For example, f(n) = n and g(n) = 𝑛2
So, in (i) n ≤ C1 𝑛2 ; but 𝑛2 ≤≠ C2 n for any C1 & C2.
4.
Let us assume that it holds ∀ m ≤ n/2 + 20
So, T(m) ≤ cm lg m ∀ m ≤ n/2 + 20
Hence we can write
T(n) = 2T( n/2 + 20 ) + n
≤ 2c (n/2+20)lg (n/2 +20) + n
≤ 2c (n/2+20)lg(n/2 +20) + n
≤ 2c(n/2+20) lg(n/2+n/4) + n
= (cn + 40c) lg(3n/4) + n
= cn lgn – cn lg 4/3 + 40c lg n – 40c lg 4/3 + n
≤ cn lgn – cn lg 4/3 + 40c lg n + n
∀ n/4 ≥ 20
As lg n = 0(n) therefore 40 c lgn ≤ kn ∀ n ≥ no hence
T(n) ≤ cn lg n + n(1- c lg 4/3) + kn
∀ n ≥ max {no , 80}
= cn lg n + n(k+1-c lg 4/3)
now we can always choose c such that
k+1 – c lg 4/3 ≤ 0
k+1 ≤ c lg 4/3
c ≥ (k+1)/ lg(4/3) = k
T(n) ≤ cn lg n
for some constant c ≥ k and n ≥ max {no , 80}………….(Hence proved)
5.
The master method does not apply to the recurrence
T(n) = 2T(n / 2) + n lg n ;
even though it has the proper form: a = 2, b = 2, f (n) = n lg n,
and nlogb a = n. It might seem that case 3 should apply, since f(n) = n lg n is
asymptotically larger than nlogb a = n. The problem is that it is not polynomially larger.
The ratio f(n) / nlogb a
= (n lg n) / n = lg n is asymptotically less than nε for any positive constant ε.
Consequently, the recurrence falls into the gap between case 2 and case 3.
T(n) = 2T(n/2) + n lg n
n
= 4T(n/4) + n lg2 + n lg n
n
n
= 8T(n/8) + n lg4 + n lg2 + n lg n
It is easy now to see that we have lg n levels costing n lg(n - i) each:
lgn
T(n) = ∑i=0 nlg(n − i)
lgn
= n∑i=0 lg(n − i)
= nlg 2 n
6.
Use changing variable technique. Let m = lg n, so n = 2m
T(n) = T(√n) + 1
m
T(2m ) = T (2 2 ) + 1
Let S(m) = T(2m ) = T(n)
m
T(2m ) = T (2 2 ) + 1
m
S(m) = S ( 2 ) + 1
By master theorem case 2, we could know that
S(m) = θ(lg m)
T(n) = θ(lg lg n)
Time complexity: θ(lg lg n)
7.
The main idea is to use the divide and conquer technique. Divide 8 coins into 2
sets and try to find the set which contains the counterfeit coin. Next, divide 4
coins into 2 sets and try to find the set which contains the counterfeit coin. Do it
by recursive.
8
2
6
Group D
2
4
Group C
2
2
Group B
Group A
Assume each group has 2 coins (named coin1 and coin2).
if (Group A != Group B)
// Counterfeit coin is in group A or B
// Coins in group C and D are real coins
if (Group A != Group C)
// Counterfeit coin is in group A
// we could know that coin1 in Group C is real coin
if (coin1 in Group A != coin1 in Group C)
coin1 in Group A is counterfeit coin
else
coin2 in Group A is counterfeit coin
else
// Counterfeit coin is in group B
// we could know that coin1 in Group C is real coin
if (coin1 in Group B != coin1 in Group C)
coin1 in Group B is counterfeit coin
else
coin2 in Group B is counterfeit coin
else
// Counterfeit coin is in group C or D
// Coins in group A and B are real coins
if (Group B != Group C)
// counterfeit coin is in Group C
// we could know that coin1 in Group A is real coin
if (coin1 in Group C != coin1 in Group A)
coin1 in Group C is counterfeit coin
else
coin2 in Group C is counterfeit coin
else
// counterfeit coin is in Group D
// we could know that coin1 in Group A is real coin
if (coin1 in Group D != coin1 in Group A)
coin1 in Group D is counterfeit coin
else
coin2 in Group D is counterfeit coin
Therefore, the minimum number of weighing is 3 = ⌈𝑙𝑔𝑛⌉
© Copyright 2026 Paperzz