





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






Hantao Zhang
http://www.cs.uiowa.edu/
∼
hzhang/c
The University of Iowa
Department of Computer Science
Time Complexity
Limits of Computation – p.1/
n
n
n
1
1
= "On input string
w
reject
if a
is found to the right of a
-s and
-s remain of the tape:
(a) Scan across the tape, crossing off a single
and a single
-s still remain after all
-s have been crossed off, or is
-s still
remain after all
-s have been crossed off
reject
. Otherwise, if neither
-s nor
-s remain of the tape,
accept
Limits of Computation – p.2/
1
Number of steps the TM has (this may depends on severalparameters).
Limits of Computation – p.3/
Limits of Computation – p.4/
Limits of Computation – p.5/
The exact running time of an algorithm may be acomplex-expression. Therefore usually this is just estimated. One convenient form of the estimation is so called
asymptotic
analysis
which determines the running time of the algorithm on large
inputs. In the asymptotic analysis one may consider only the highest orderterm of the expression for the running time of the algorithm,disregarding both the coefficient of that term and any lower orderterms. This is valid because the value of the highest order term dominatesthe value of other terms on large inputs.
Limits of Computation – p.6/
3
2
Disregarding the coefficient
, we say that
f
is asymptotically at most
n
3
The asymptotic notation, or big-O notation for describing theestimation defined by
f
n
is
f
n
n
3
Limits of Computation – p.7/
0
0
Limits of Computation – p.8/
n
→∞
f
(
n
)
g
(
n
)
any
0
0
Limits of Computation – p.13/
n
o
n
n
o
n log
log
n
n log
log
n
o
n log
n
n log
n
o
n
2
n
2
o
n
3
f
n
is never
o
f
n
Limits of Computation – p.14/
1
n
n
n
1
= "On input string
w
reject
if a
is found to the right of a
-s and
-s remain of the tape:
(a) Scan across the tape, crossing off a single
and a single
-s still remain after all
-s have been crossed off, or is
-s still
remain after all
-s have been crossed off
reject
. Otherwise, if neither
-s nor
-s remain of the tape,
accept
Limits of Computation – p.15/
n
steps to verify that the
input is of the form
∗
∗
; repositioning the tape at the left end uses
another
n
steps. So, the total number of steps is
n
, i.e.,
n
n
Because each scan crosses off a
and a
, at most
n/
scans occur.
I.e., the total number of steps is
n/
n
n
2
accept or reject taking
n
steps
Total number of steps is
n
n
2
n
n
2
Limits of Computation – p.16/
Since language
n
n
n
is decided by
1
in
n
2
steps,
n
2
n
2
contains all languages decidable in
n
2
time.
Is there a TM that decides
asymptotically faster? I.e.,is
in
t
n
for
t
n
o
n
2
? One can cross 2
’s and 2
’s in stage 2
which cuts the number of scans by half but running time does notchange.
Limits of Computation – p.17/
2
= "On input string
w
reject
if a 0 is found to the right of a 1
’s and some
’s remain on the tape:
(a) Scan across the tape, checking whether the total number of
’s
and
’s remaining on the tape is even or odd. If it is odd
reject
(b) Scan again across the tape, crossing every other 0 starting with
the first 0, and then crossing off every other 1 starting with thefirst 1
’s and no
’s remain of the tape,
accept
; otherwise
reject
Limits of Computation – p.18/
n
steps
log
2
n
n
n log
n
n
steps
n
steps
Total number of steps is asymptotically
n log
2
n
, that is,
n log n
Note:
any language that can be decided in
o
n log n
on a single-tape TM
is regular; since
is not regular no faster algorithm performed by a single-
tape TM exists to decide it.
Limits of Computation – p.19/
3
3
= "On input string
w
on tape 1:
’s on tape 1 until the first 1; at the same time copy
the
’s on tape 2.
’s on tape 1 until the end of the tape is discovered.
For each 1 read on tape 1, cross off a 0 on tape 2. If all
’s are
crossed off before all 1 are read
reject
’s have been crossed off
accept
; if any
’s remain
reject
Limits of Computation – p.20/
For
a
k
-tape TM that runs in
t
n
time, the single-tape TM
operates
as follows:
puts its tape into the format that represents all the
k
-tapes
of
and then simulates
scan all the info stored on its tape to
determine the symbol under
’s heads.
makes another pass over its tape to update the tape contents
and head positions.
’s heads moves rightward onto a previously unread
position on its tape,
must increase the amount of space by shifting
a portion of its tape one cell to the right
Limits of Computation – p.25/
For each step of
makes two passes over the active portion of its
tape: first to obtain the info necessary to determine the next moveand second to carry out the move. The upper-bound of the length of the active portion of
’s tape is the
sum of the length of active portions of
’s
k
tapes, which are
bounded by
t
n
, i.e., upper-bound of the active portion of
’s tape is
t
n
Limits of Computation – p.26/
To simulate each of
’s steps,
performs two scans, each using
t
n
time, i.e., one step of
is simulated by
in
t
n
time.
Sine by assumption
perform
t
n
steps, total time taken by
to
simulate
is
t
n
taken by the initial step plus
t
n
t
n
to
perform the simulation, i.e., time complexity of
is
t
2
n
Limits of Computation – p.27/
Limits of Computation – p.28/
Limits of Computation – p.29/
f
(
n
)
p
accept/reject
? p?
...
p ?p ?p?
Deterministic
p
p
p
p
p
p
p
p
...
p
accept
p
reject
Nondeterministic
f
(
n
)
Measuring deterministic and nondeterministic time
Limits of Computation – p.30/
Limits of Computation – p.31/
O
(
t
(
n
))
Let
be a nondeterministic TM running in time
t
n
. We con-
struct a deterministic TM
that simulates
by searching
’s nondeter-
ministic computation tree
Limits of Computation – p.32/