• Please give details of your answer. A direct answer without explanation is not
counted.
• Your answers must be in English.
• Please carefully read problem statements.
• During the exam you are not allowed to borrow others’ class notes.
• Try to work on easier questions first.
Problem 1
(10 pts)
If we would like to prove
f (n) 6= O(g(n)),
we need to show the opposite statement of the definition of
f (n) = O(g(n)).
What is this opposite statement?
Answer
∀c > 0, N ∈ N, ∃n ≥ N
such that
f (n) > cg(n).
Problem 2
(25 pts)
Consider the following two functions
n3 ,
f (n) =
n2 ,
n3 ,
g(n) =
n2 ,
if n is odd
if n is even
if n is prime
if n is composite
Which of the following statements are true?
(a) f = O(n2 )
1
(b) f = O(n3 )
(c) g = O(n2 )
(d) g = O(n3 )
(e) f = O(g)
(f) g = O(f )
(g) n2 = O(f )
(h) n3 = O(f )
(i) n2 = O(g)
(j) n3 = O(g)
You must prove the result of each sub-problem. If you think the statement is false, you should
prove the definition that you wrote for problem 1.
Answer
Statements (b), (d), (f), (g), (i) are true.
(a) For any c > 0, N ∈ N, we can let
n = an odd number larger than c and N.
Then
f (n) = n3 > cn2
⇒f 6= O(n2 ).
(b) Let c = 1 and N = 1.
cn3 ≥ n2
∀n ≥ N
⇒cn3 ≥ f (n) ∀n ≥ N
⇒f = O(n3 ).
(c) For any c > 0, N ∈ N, we can let
n = a prime number larger than c and N.
Then
g(n) = n3 > cn2
⇒g 6= O(n2 ).
2
(d) Let c = 1 and N = 1.
cn3 ≥ n2
∀n ≥ N
⇒cn3 ≥ g(n) ∀n ≥ N
⇒g = O(n3 ).
(e) For any c > 0, N ∈ N, we can let
n = an odd and composite number larger than c and N.
Then
f (n) = n3 > cg(n) = cn2
⇒f 6= O(g).
(f) Let c = 1 and N = 3.
Because all of the prime numbers except 2 are odd,
cf (n) = cn3 ≥ g(n) = n3 , when n is prime and n 6= 2
and
cn3
≥ g(n) = n2 , when n is composite.
cf (n) =
cn2
Therefore,
cf (n) ≥ g(n) ∀n ≥ N
⇒g = O(f ).
(g) Let c = 1 and N = 1.
cn3 ≥ n2
∀n ≥ N
⇒cf (n) ≥ n2
∀n ≥ N
⇒n2 = O(f ).
(h) For any c > 0, N ∈ N, we can let
n = an even number larger than c and N.
Then
n3 > cf (n) = cn2
⇒n3 6= O(f ).
(i) Let c = 1 and N = 1.
cn3 ≥ n2
⇒cg(n) ≥ n2
⇒n2 = O(g).
3
∀n ≥ N
∀n ≥ N
(j) For any c > 0, N ∈ N, we can let
n = a composite number larger than c and N.
Then
n3 > cg(n) = cn2
⇒n3 6= O(g).
Common Mistakes
1. You cannot have a statement like
if n is even, then n2 = O(n3 ).
Note that big-O is for a function of
N →N
2. To prove that the statement is false, many write “we can find n ≥ N such that . . . if n is
composite”. If you already “find” an n, then n may not be composite.
3. Some write
no matter f (n) = n2 or n3 , since n2 = O(n2 ) and n2 = O(n3 ), then n2 = O(f ).
We didn’t really have such a statement. You need to prove it by the definition.
Problem 3
(20 pts)
Assume g(n) ≥ n. Consider O(2f (n) ) and 2O(f (n)) . Do we have
g(n) = O(2f (n) )
⇒ g(n) = 2O(f (n))
or
g(n) = 2O(f (n))
⇒ g(n) = O(2f (n) )
4
Answer
(a) We will show that
g(n) = O(2f (n) )
⇒ g(n) = 2O(f (n))
is true.
Proof:
Since g(n) ≥ n and g(n) = O(2f (n) ), ∃c1 > 0, N1 ≥ 1, s.t.
n ≤ g(n) ≤ c1 2f (n) , ∀n ≥ N1 ,
(1)
To prove that g(n) = 2O(f (n)) , we must prove that
g(n) ≤ c1 2f (n) ≤ 2c2 f (n) , ∀n ≥ N2 .
is true for some c2 > 0, N2 ≥ N1 .
Which means we should prove that ∃c2 > 1, N2 ≥ N1 s.t. ∀n ≥ N2 ,
log c1 + f (n) ≤ c2 f (n)
log c1
⇒f (n) ≥
.
c2 − 1
According to (1), we have
log n ≤ log c1 + f (n)
⇒f (n) ≥ log n − log c1
Therefore, we should prove that ∃c2 > 1, N2 ≥ N1 , s.t.
log n − log c1 ≥
⇒ log n ≥
log c1
c2 − 1
c2
log c1
c2 − 1
This is always true when n becomes large.
So given c1 , N1 , ∃c2 = 2, N2 = max{N1 , 4c1 } , such that (2) is true.
Therefore, g(n) = 2O(f (n)) .
(b) We will show that
g(n) = 2O(f (n))
⇒ g(n) = O(2f (n) )
5
(2)
is not true.
Proof:
Let g(n) = 22n , f (n) = n. Since
g(n) ≤ 22f (n) for n ≥ 1,
we have
g(n) = 2O(f (n)) .
Assume g(n) = O(2f (n) ). There are c > 0, N ≥ 1, such that ∀n ≥ N,
22n ≤ c · 2n ,
⇒ 2n ≤ c, ∀n ≥ N.
However, we can’t find a constant c to satisfy 2n ≤ c, ∀n ≥ N , because the left side of the
inequality goes to infinity when n → ∞. Therefore, there is a contradiction.
Common Mistakes
1. In your proof (a), the property g(n) ≥ n should be used.
2. Many wrongly have
2a · 2b = 2ab .
3. Some write
f (n) ≥ log n − log c
⇒f (n) is a strictly increasing function.
This may not be true.
Problem 4
(20 pts)
Consider
f (n) = log(1 + en )
g(n) = n
h(n) = n2
Which of the following statements are true? For small-o, you can directly calculate the limit
without getting into the definition of limit.
6
(a) f (n) = O(g(n))
(b) f (n) = o(g(n))
(c) f (n) = O(h(n))
(d) f (n) = o(h(n))
Answer
Statement (a),(c),(d) are true.
(a) ∵ f (n) = log(1 + en ) < log(2en ) = log(2) + n ≤ 2n, for n ≥ 1
∴ ∃c = 2, N = 1, s.t. ∀n ≥ N
f (n) ≤ cn
∴ f (n) = O(n) = O(g(n)).
(b) According to L’Hospital Rule,
en
f (n)
f 0 (n)
1
n
lim
= lim 0
= lim 1+e = lim (1 −
) = 1.
n→∞ g(n)
n→∞ g (n)
n→∞ 1
n→∞
1 + en
Therefore, f (n) 6= o(g(n))
(c) Since n2 ≥ n, from sub-problem (a), ∃c = 2, N = 1 such that
f (n) ≤ cn ≤ cn2 , ∀n ≥ N.
Therefore, f (n) = O(h(n))
(d) According to L’Hospital Rule,
en
f (n)
n
lim
= lim 1+e = 0.
n→∞ h(n)
n→∞ 2n
Therefore, f (n) = o(h(n))
Common Mistakes
1. Some write
log(1 + en )
log(en )
lim
= lim
,
n→∞
n→∞
n
n
but which basic properties of limit give you this?
7
Problem 5
(5 pts)
Is the following language Turing recognizable?
ĀT M = {hM, wi | hM, wi 6∈ AT M },
where
AT M = {hM, wi | M is a TM and accepts w}
Answer
It is not Turing recognizable.
We know that AT M is Turing recognizable but undecidable. (Theorem 4.11)
Assume that ĀT M is Turing recognizable.
Then AT M is both co-Turing recognizable and Turing recognizable. By Theorem 4.22 in the
textbook, AT M is decidable.
However, we have proved that AT M is not decidable, so there is a contradiction.
Common Mistakes
1. Some write
undecidable ⇒ un-recognizable.
This is incorrect. AT M is undecidable, but recognizable.
Problem 6
(20 pts)
Consider the following language
A = {hR, Si | R and S are regular expressions and L(R) ⊆ L(S)}
Is it decidable?
Answer
Yes, it is decidable.
8
We first observe that
L(R) ⊆ L(S) iff ∀w ∈ L(R), w ∈ L(S)
iff ∀w ∈ L(R), w 6∈ L(S)
iff L(R) ∩ L(S) = ∅
We can construct a DFA C such that
L(C) = L(R) ∩ L(S)
with
1. The conversion of regular expressions to an equivalent NFA (procedures in Theorem 1.54).
2. Constructions for proving closure of regular languages under complementation and intersection.
3. Conversion from NFA to DFA.
We can then use Theorem 4.4 to test if L(C) = L(R) ∩ L(S) is empty.
The following TM F decides A:
On input hR, Si, where R and S are regular expressions.
1. Construct DFA C as described.
2. Run TM T from Theorem 4.4 on input hCi.
3. If T accepts, accept. If T rejects, reject.
9
© Copyright 2026 Paperzz