Complexity Measures and Classes Deterministic Complexity Measures: Time and Space
Deterministic Time and Space Complexity Measures
Definition
LetMbe any DTM withL(M)⊆Σ∗, and letx ∈Σ∗ be any input. For the computationM(x), define thetime functionand thespace function, denoted respectively byTimeM andSpaceM, both of which map fromΣ∗ toN, as follows:
TimeM(x) =
m ifM(x)has exactlym+1configurations undefined otherwise;
SpaceM(x) =
number of tape cells in a largest
configuration ofM(x) ifM(x)terminates
undefined otherwise.
Complexity Measures and Classes Deterministic Complexity Measures: Time and Space
Blum’s Axioms
Letϕ0, ϕ1, ϕ2, . . .be a fixed G ¨odelization (i.e., an effective enumeration) of all one-argument functions inIP, the class of all partial recursive (i.e., computable) functions.
LetIRbe the class of all total (i.e., everywhere defined) recursive functions.
LetΦ∈IPbe a function mapping fromN×Σ∗ toN, and write Φi(x)as a shorthand forΦ(i,x).
We say thatΦis aBlum complexity measureif and only if the following two axioms are satisfied:
Axiom 1: For eachi ∈N,DΦi =Dϕi. Axiom 2: The set{(i,x,m)
Φi(x) =m}is decidable.
Complexity Measures and Classes Deterministic Complexity Measures: Time and Space
Deterministic Time and Space Complexity Measures
Definition (continued)
Define the functionstimeM :N→NandspaceM :N→Nby:
timeM(n) =
x:|x|=nmax TimeM(x) if TimeM(x)is defined for eachx with|x|=n undefined otherwise;
spaceM(n) =
x:|x|=nmax SpaceM(x) if SpaceM(x)is defined for eachx with|x|=n undefined otherwise.
Complexity Measures and Classes Deterministic Complexity Measures: Time and Space
Deterministic Time and Space Complexity Classes
Definition
Lettandsbe functions inIRmapping fromNtoN.
Define the followingdeterministic complexity classes with resource function t and s, respectively:
DTIME(t) =
A A=L(M)for some DTMMand, for eachn∈N, timeM(n)≤t(n)
;
DSPACE(s) =
A A=L(M)for some DTMMand, for eachn∈N, spaceM(n)≤s(n)
.
Complexity Measures and Classes Deterministic Complexity Measures: Time and Space
Deterministic Time and Space Complexity Classes
Remark:
Note that a deterministic Turing machineM decidesits language.
IfA=L(M)then bothtimeM(n)andspaceM(n)are defined for each n∈N.
In contrast, a nondeterministic Turing machineacceptsits language. Thus, the nondeterministic case is treated slightly differently.
The resource functionst ands in are called thenamesof DTIME(t)andDSPACE(s), respectively.
Complexity Measures and Classes Deterministic Complexity Measures: Time and Space
Deterministic Time and Space Complexity Classes
Remark:
IfMis a Turing machine with more than one tape, thenSpaceM(x), the size of “a largest configuration ofM(x),” is defined to be the maximum number of tape cells, where the maximum is taken both
over all tapes and
over all configurations in the computation.
If there is a separate read-only input tape, then only the space used on the working tapes is to be taken into account (reasonable due to sublinear space functions such as logarithmic space).
Complexity Measures and Classes Nondeterministic Complexity Measures: Time and Space
Nondeterministic Time and Space Measures
Definition
LetMbe any NTM withL(M)⊆Σ∗, and letx ∈Σ∗ be any input.
LetTimeM(x, α)andSpaceM(x, α)denote thetimeandspacefunctions for each pathαinM(x). For the computationM(x), define the
nondeterministictimeandspacefunction, denoted byNTimeM and NSpaceM, both of which map fromΣ∗ toN, as follows:
NTimeM(x) =
M(x)accepts on pathmin αTimeM(x, α) ifx ∈L(M)
undefined otherwise;
NSpaceM(x) =
M(x)accepts on pathmin αSpaceM(x, α) ifx ∈L(M)
undefined otherwise.
Complexity Measures and Classes Nondeterministic Complexity Measures: Time and Space
Nondeterministic Time and Space Measures
Definition (continued)
Lettandsbe functions inIRmapping fromNtoN. We say thatM accepts a set A in time t if
for eachx ∈A, we haveNTimeM(x)≤t(|x|), and for eachx 6∈A,M does not acceptx.
We say thatM accepts a set A in space sif
for eachx ∈A, we haveNSpaceM(x)≤s(|x|), and for eachx 6∈A,M does not acceptx.
Complexity Measures and Classes Nondeterministic Complexity Measures: Time and Space
Nondeterministic Time and Space Complexity Classes
Definition (continued)
Define the followingnondeterministic complexity classes with resource function t and s, respectively:
NTIME(t) =
A A=L(M)for some NTMM that acceptsAin timet(n)
;
NSPACE(s) =
A A=L(M)for some NTMM that acceptsAin spaces(n)
.
Complexity Measures and Classes Resource Functions
Resource Functions
Remark:
It is reasonable to consider collectionsF of “similar” resource functions and to define the complexity class corresponding toF by
DTIME(F) = [
f∈F
DTIME(f)
etc.
Such a collectionF contains all resource functions with asimilar rate of growth.
Complexity Measures and Classes Resource Functions
Resource Functions
Remark:
Consider the collections of functions mapping fromNtoNeach:
ILincontains all linear functions, IPolcontains all polynomials,
2ILincontains all exponential functions whose exponent is linear inn, and
2IPolcontains all exponential functions whose exponent is polynomial inn.
More generally, for any functiont :N→N, define the collection of all functions linear int(respectively, polynomial int) by:
ILin(t) = {f
f =`◦tand`∈ILin};
IPol(t) = {f
f =p◦t andp∈IPol}.
Complexity Measures and Classes Asymptotic Rate of Growth
Asymptotic Rate-of-Growth Notation
Definition
For functionsf andg mapping fromNtoN, define the following notation:
f(n)≤aeg(n)to mean thatf(n)≤g(n)is true for all but finitely manyn∈N.
Analogously, the notations <ae, ≥ae, and >ae are defined.
The subscript “ae” of “≤ae,” etc. stands for “almost everywhere.”
Similarly, the notationf(n)≤iog(n)means thatf(n)≤g(n)is true for infinitely manyn∈N.
Analogously, the notations <io, ≥io, and >io are defined.
The subscript “io” of “≤io,” etc. stands for “infinitely often.”
Complexity Measures and Classes Asymptotic Rate of Growth
Asymptotic Rate-of-Growth Notation
Definition
For functionsf andg mapping fromNtoN, define the following notation:
f ∈ O(g) ⇐⇒ there is a real constantc >0 such that f(n) +1 ≤ae c·(g(n) +1).
f ∈o(g) ⇐⇒ for all real constantsc>0, f(n) +1 <ae c·(g(n) +1).
Complexity Measures and Classes Asymptotic Rate of Growth
Asymptotic Rate-of-Growth Notation
Definition
f g ⇐⇒ lim supn→∞ g(n)+1f(n)+1 <∞.
Note thatf ∈ O(g) ⇐⇒ f g.
Intuitively,f g means that, by order of magnitude,f does not grow faster thang, with at most finitely many exceptions allowed.
f ≺g ⇐⇒ lim supn→∞ g(n)+1f(n)+1 =0.
Note thatf ∈o(g) ⇐⇒ f ≺g.
Intuitively,f ≺g means that, by order of magnitude,g does grow strictly faster thanf, with at most finitely many exceptions allowed.
Complexity Measures and Classes Asymptotic Rate of Growth
Asymptotic Rate-of-Growth Notation
Definition
fiog ⇐⇒ lim infn→∞ f(n)+1 g(n)+1 <∞.
Intuitively,fiog means that, by order of magnitude,f does not grow faster thang, at least not for infinitely many arguments.
f≺iog ⇐⇒ lim infn→∞ f(n)+1 g(n)+1 =0.
Intuitively,f≺iog means that, by order of magnitude,gdoes grow strictly faster thanf, at least for infinitely many arguments.
Complexity Measures and Classes Asymptotic Rate of Growth
Asymptotic Rate-of-Growth Notation
Remark:
1 The additive constant 1 in the denominators of the limit
expressions above merely ensures that the denominator in g(n)+1f(n)+1 is distinct from zero, so the quotient is well-defined.
2 For expressions such aslim supn→∞ g(n)+1f(n)+1, the additive constant 1 in the enumerator prevents it from going to zero withoutg growing strictly faster thanf.
For example, the constant functions 0 and 2, which do not grow at all, should satisfy 020. Without the additive 1, however, we had 0≺2, which is not desirable.
Complexity Measures and Classes Asymptotic Rate of Growth
Asymptotic Rate-of-Growth Notation
Definition Write
f gforg f, f gforg ≺f, fiog forgiof, and fiog forg≺iof.
Complexity Measures and Classes Asymptotic Rate of Growth
Asymptotic Rate-of-Growth Notation
Example
1 logn≺n.
2 n2nand 2nn.
3 For
f(n) = n(nmod2) +n2((n+1) mod2) and g(n) = n2(nmod2) +n((n+1) mod2) we simultaneously havef≺iog andg≺iof.
4 If, in addition,h(n) =n2, we simultaneously have f h and f≺ioh and hiof.
Complexity Measures and Classes Some Central Worst-Case Complexity Classes
Some Central Worst-Case Complexity Classes
Space classes
L = DSPACE(log) NL = NSPACE(log) LINSPACE = DSPACE(ILin) NLINSPACE = NSPACE(ILin) PSPACE = DSPACE(IPol) NPSPACE = NSPACE(IPol) EXPSPACE = DSPACE(2IPol) NEXPSPACE = NSPACE(2IPol)
Complexity Measures and Classes Some Central Worst-Case Complexity Classes
Some Central Worst-Case Complexity Classes
Time classes REALTIME = DTIME(id)
LINTIME = DTIME(ILin) P = DTIME(IPol) NP = NTIME(IPol) E = DTIME(2ILin) NE = NTIME(2ILin) EXP = DTIME(2IPol) NEXP = NTIME(2IPol)
Complexity Measures and Classes Some Central Worst-Case Complexity Classes
Polynomial versus Exponential Functions
t(n) n=10 n=20 n=30
n .00001 sec .00002 sec .00003 sec
n2 .0001 sec .0004 sec .0009 sec
n3 .001 sec .008 sec .027 sec
n5 .1 sec 3.2 sec 24.3 sec
2n .001 sec 1.0 sec 17.9 min
3n .059 sec 58 min 6.5 years
Table:Comparing some functions (Garey & Johnson 1979)
Complexity Measures and Classes Some Central Worst-Case Complexity Classes
Polynomial versus Exponential Functions
t(n) n=40 n=50 n=60
n .00004 sec .00005 sec .00006 sec
n2 .0016 sec .0025 sec .0036 sec
n3 .064 sec .125 sec .256 sec
n5 1.7 min 5.2 min 13.0 min
2n 12.7 days 35.7 years 366 centuries 3n 3855 centuries 2·108centuries 1.3·1013centuries
Table:Comparing some functions (Garey & Johnson 1979)
Complexity Measures and Classes Some Central Worst-Case Complexity Classes
What if the Computers Get Faster?
ti(n) Computer 100 times 1000 times
today faster faster
t1(n) =n N1 100·N1 1000·N1 t2(n) =n2 N2 10·N2 31.6·N2 t3(n) =n3 N3 4.64·N3 10·N3 t4(n) =n5 N4 2.5·N4 3.98·N4 t5(n) =2n N5 N5+6.64 N5+9.97 t6(n) =3n N6 N6+4.19 N6+6.29 Table:What if the computers get faster? (Garey & Johnson 1979)
Complexity Measures and Classes Some Central Worst-Case Complexity Classes
Time versus Space for Deterministic Classes
Theorem
1 DTIME(t)⊆DSPACE(t).
2 DSPACE(s)⊆DTIME(2ILin(s))if s≥log.
Proof:
1 The first statement is immediately clear, since in timetany Turing machine can move its heads by at mostt tape cells.
2 To prove the second statement, letMbe a DTM working in space s(n)and in timet(n). SupposeM has
qstates,
k working tapes and one input tape, and a working alphabet with`symbols.
Complexity Measures and Classes Some Central Worst-Case Complexity Classes
Time versus Space for Deterministic Classes
For each inputx of lengthn,M’s time boundt(n)is bounded above by the number of distinct configurations ofM(x).
To see why, note that if there were one configuration occurring twice in the computation ofM(x), then sinceM works deterministically, it would loop forever and would never halt, a contradiction.
How many distinct configurations canM(x)have?There are q possible states,
npossible head positions on the input tape,
(s(n))k possible head positions on thek working tapes, and
`k·s(n)possible tape inscriptions.
Complexity Measures and Classes Some Central Worst-Case Complexity Classes
Time versus Space for Deterministic Classes
Hence, there exist suitable positive constantsa,b, andcsuch that:
t(n) ≤ q·n·(s(n))k ·`k·s(n)
≤ q·2logn·2a·s(n)
≤ q·2b·s(n)
≤ 2c·s(n),
where the third inequality uses the assumption thats≥log.
Thus,tis in 2ILin(s). q
Complexity Measures and Classes Some Central Worst-Case Complexity Classes
Best Wishes for Christmas!
Complexity Measures and Classes Some Central Worst-Case Complexity Classes
Best Wishes for Christmas! Unless ... Well ...
Merkel