Lecture 21
Lecture 21
Big-Oh notation.
Little-o notation.
Time Complexity Classes
Non-deterministic TMs
The Class P
Let
A = {0k 1k : k ≥ 0}
we saw an algorithm that accepts A in time O(n2 ).
f (n) ≤ cg (n).
Let
f (n) = 13n4 + 7n2 + 13
then
f (n) = O(n4 ).
Furthermore,
f (n) = O(n5 ).
But it is not true that
f (n) = O(n3 )
Suppose that
f (n) = logb n
where b is a constant. Note that
log2 n
logb n = .
log2 b
2O(n)
2cn
2O(log n) .
Well remember that O(log n) has a constant attached to it. Thus this
function is upper bounded by
2c log n
for some constant c. Now, we get
2c log n = (2log n )c = nc .
if
f (n)
lim = 0.
n→∞ g (n)
√
1 n = o(n)
2 n = o(n log log n)
3 n log log n = o(n log n)
4 n log n = o(n2 )
5 n2 = o(n3 )
A = {0k 1k : k ≥ 0}.
1 Scan the tape and make sure all the 0s are before 1s.
2 Repeat till there are 0s and 1s on the tape.
1 Scan the tape and if the total number of 0s and 1s is odd reject.
2 Scan and cross of every other 0 and do the same with every other 1.
3 If all 0s and 1s are crossed accept.
Thus if we have 13 0s in the next stage there would be 6.
O(nlogn)
nlogn = o(n2 ).
So for example:
1 TIME(n) is the set of all languages, L, for which there is a linear time
TM that accepts L.
2 TIME(n2 ) is the set of all languages, L, for which there is a quadratic
time TM that accepts L.
Recall
A = {0k 1k : k ≥ 0}.
Our first algorithm (or TM) showed that
A ∈ TIME(n2 ).
Notice that
TIME(nlogn) ⊆ TIME(n2 ).
The proof of the theorem is just a more careful study of the previous
proof. Remember given a k-Tape TM, M, we made a 1-tape TM, N. N
works as follows:
1 On input x convert the input to #q0#x# · · · # the start
configuration of M. This configuration says that x is on the first
tape. The rest of the tapes are empty and the machine is in q0 .
2 In each pass over the tape change the current configuration to the
next one.
3 If an accepting configuration is reached accept
4 If a rejecting configuration is reached reject.
Now, we just have to estimate how much time does N require.
t(n) ≥ n.
In the first step the machine converts x to the initial configuration. This
takes time O(n). Thus the total time is actually
2O(t(n))
Thus this theorem says that we can get rid of non-determinism at the cost
of exponentiating the time!
1 + b + b 2 + · · · + b t(n) ≤ 2b t(n) .
For each string s the simulation can take O(t(n)) time. There are b t(n)
strings to simulate. Thus the total time is
Our last part is to convert this multi-tape TM into a single tape TM. If we
use the previous theorem then the total time would be