• 沒有找到結果。

# A 2-String TM

N/A
N/A
Protected

Share "A 2-String TM"

Copied!
58
0
0

(1)

### Turing Machines with Multiple Strings

• A k-string Turing machine (TM) is a quadruple M = (K, Σ, δ, s).

• K, Σ, s are as before.

• δ : K × Σk → (K ∪ {h, “yes”, “no”}) × (Σ × {←, →, −})k.

• The ﬁrst string contains the input.

• Decidability and acceptability are the same as before.

• When TMs compute functions, the output is the last

(2)

### A 2-String TM

δ

#1000110000111001110001110

#111110000

(3)

### palindrome Revisited

• A 2-string TM can decide palindrome in O(n) steps.

– It copies the input to the second string.

– The cursor of the ﬁrst string is positioned at the ﬁrst symbol of the input.

– The cursor of the second string is positioned at the last symbol of the input.

– The symbols under the cursors are then compared.

– The two cursors are then moved in opposite directions until the ends are reached.

– The machine accepts if and only if the symbols under

(4)

δ

#ababbaabbaabbaabbaba

#ababbaabbaabbaabbaba

(5)

### palindrome Revisited (concluded)

• The running times of a 2-string TM and a single-string TM are quadratically related: n2 vs. n.

• This is consistent with the extended Church’s thesis (p.

66).

– “Reasonable” models are related polynomially in running times.

(6)

### Configurations and Yielding

• The concept of conﬁguration and yielding is the same as before except that a conﬁguration is a (2k + 1)-tuple

(q, w1, u1, w2, u2, . . . , wk, uk).

– wiui is the ith string.

– The ith cursor is reading the last symbol of wi. – Recall that  is each wi’s ﬁrst symbol.

• The k-string TM’s initial conﬁguration is

(s,

 2k 

, x,, ,, , . . . ,, ).

(7)

Time seemed to be the most obvious measure of complexity.

— Stephen Arthur Cook (1939–)

(8)

### Time Complexity

• The multistring TM is the basis of our notion of the time expended by TMs.

• If a k-string TM M halts after t steps on input x, then the time required by M on input x is t.

• If M(x) =, then the time required by M on x is ∞.

(9)

### Time Complexity (concluded)

• Machine M operates within time f(n) for f : N → N if for any input string x, the time required by M on x is at most f (| x |).

| x | is the length of string x.

• Function f(n) is a time bound for M.

(10)

### Time Complexity Classes

a

• Suppose language L ⊆ (Σ − {

}) is decided by a multistring TM operating in time f (n).

• We say L ∈ TIME(f(n)).

• TIME(f(n)) is the set of languages decided by TMs

with multiple strings operating within time bound f (n).

• TIME(f(n)) is a complexity class.

– palindrome is in TIME(f (n)), where f (n) = O(n).

• Trivially, TIME(f(n)) ⊆ TIME(g(n)) if f(n) ≤ g(n) for all n.

(11)

a

(12)

a

### (1936–)

aTuring Award (1993).

(13)

### The Simulation Technique

Theorem 3 Given any k-string M operating within time f (n), there exists a (single-string) M operating within time O(f (n)2) such that M (x) = M(x) for any input x.

• The single string of M implements the k strings of M .

(14)

### The Proof

• Represent conﬁguration (q, w1, u1, w2, u2, . . . , wk, uk) of M by this string of M:

(q,w1 u1  w2 u2  · · ·  wkuk  ).

 is a special delimiter.

– wi is wi with the ﬁrsta and last symbols “primed.”

– It serves the purpose of “,” in a conﬁguration.b

aThe ﬁrst symbol is of course .

bAn alternative is to use (q, w1|u1  w2|u2  · · ·  wk |uk  ) by priming only  in wi, where “|” is a new symbol.

(15)

### The Proof (continued)

• The ﬁrst symbol of wi is the primed version of : . – Recall TM cursors are not allowed to move to the left

of  (p. 23).

– Now the cursor of M can move between the simulated strings of M .a

• The “priming” of the last symbol of each wi ensures that M knows which symbol is under each cursor of M .b

aThanks to a lively discussion on September 22, 2009.

(16)

### The Proof (continued)

• The initial conﬁguration of M is

(s,   x 

k − 1 pairs

  

  · · ·   ).

 is double-primed because it is the beginning and the ending symbol as the cursor is reading it.a

– Again, think of it as a new symbol.

aAdded after the class discussion on September 20, 2011.

(17)

### The Proof (continued)

• We simulate each move of M thus:

1. M scans the string to pick up the k symbols under the cursors.

– The states of M must be enlarged to include K × Σk to remember them.a

– The transition functions of M must also reﬂect it.

2. M then changes the string to reﬂect the overwriting of symbols and cursor movements of M .

aRecall the TM program on p. 31.

(18)

### The Proof (continued)

• It is possible that some strings of M need to be lengthened (see next page).

– The linear-time algorithm on p. 37 can be used for each such string.

• The simulation continues until M halts.

• M then erases all strings of M except the last one.a

aBecause whatever appears on the string of M will be considered the output. So s and s need to be removed.

(19)

a

### string 1 string 2 string 3 string 4

aIf we interleave the strings, the simulation may be easier. Con- tributed by Mr. Kai-Yuan Hou (B99201038, R03922014) on September 22, 2015. This is similar to constructing a single-string multi-track TM in, e.g., Hopcroft & Ullman (1969).

(20)

### The Proof (continued)

• Since M halts within time f(| x |), none of its strings ever becomes longer than f (| x |).a

• The length of the string of M at any time is O(kf (| x |)).

• Simulating each step of M takes, per string of M, O(kf (| x |)) steps.

– O(f (| x |)) steps to collect information from this string.

– O(kf (| x |)) steps to write and, if needed, to lengthen the string.

a

(21)

### The Proof (concluded)

• M takes O(k2f (| x |)) steps to simulate each step of M because there are k strings.

• As there are f(| x |) steps of M to simulate, M operates within time O(k2f (| x |)2).a

aIs the time reduced to O(kf(| x |)2) if the interleaving data structure is adopted?

(22)

### Simulation with Two-String TMs

We can do better with two-string TMs.

Theorem 4 Given any k-string M operating within time f (n), k > 2, there exists a two-string M operating within time O(f (n) log f (n)) such that M (x) = M(x) for any input x.

(23)

### Linear Speedup

a

Theorem 5 Let L ∈ TIME(f(n)). Then for any  > 0, L ∈ TIME(f(n)), where f(n) = f (n) + n + 2.Δ

See Theorem 2.2 of the textbook for a proof.

aHartmanis & Stearns (1965).

(24)

### Implications of the Speedup Theorem

• State size can be traded for speed.a

• If the running time is cn with c > 1, then c can be made arbitrarily close to 1.

• If the running time is superlinear, say 14n2 + 31n, then the constant in the leading term (14 in this example) can be made arbitrarily small.

– Arbitrary linear speedup can be achieved.b

– This justiﬁes the big-O notation in the analysis of algorithms.

amk · |Σ|3mk-fold increase to gain a speedup of O(m). No free lunch.

b

(25)

### P

• By the linear speedup theorem, any polynomial time bound can be represented by its leading term nk for some k ≥ 1.

• If L ∈ TIME(nk) for some k ∈ N, it is a polynomially decidable language.

– Clearly, TIME(nk) ⊆ TIME(nk+1).

• The union of all polynomially decidable languages is denoted by P:

P =Δ 

k>0

TIME(nk).

(26)

Philosophers have explained space.

They have not explained time.

— Arnold Bennett (1867–1931), How To Live on 24 Hours a Day (1910) I keep bumping into that silly quotation attributed to me that says 640K of memory is enough.

— Bill Gates (1996)

(27)

### Space Complexity

• Consider a k-string TM M with input x.

• Assume non-

is never written over by  .a

– The purpose is not to artiﬁcially reduce the space needs (see below).

• If M halts in conﬁguration

(H, w1, u1, w2, u2, . . . , wk, uk),

then the space required by M on input x is

k i=1

| wiui |.

(28)

### Space Complexity (continued)

• Suppose we do not charge the space used only for input and output.

• Let k > 2 be an integer.

• A k-string Turing machine with input and output is a k-string TM that satisﬁes the following conditions.

– The input string is read-only.a

– The cursor on the last string never moves to the left.

∗ The output string is essentially write-only.

– The cursor of the input string does not wander oﬀ into the 

s.

(29)

### Space Complexity (concluded)

• If M is a TM with input and output, then the space required by M on input x is

k−1

i=2

| wiui |.

• Machine M operates within space bound f(n) for f : N → N if for any input x, the space required by M on x is at most f (| x |).

(30)

### Space Complexity Classes

• Let L be a language.

• Then

L ∈ SPACE(f(n))

if there is a TM with input and output that decides L and operates within space bound f (n).

• SPACE(f(n)) is a set of languages.

– palindrome ∈ SPACE(log n).a

• A linear speedup theorem similar to the one on p. 93 exists, so constant coeﬃcients do not matter.

(31)

If she can hesitate as to “Yes,”

she ought to say “No” directly.

— Jane Austen (1775–1817), Emma (1815)

(32)

### Nondeterminism

a

• A nondeterministic Turing machine (NTM) is a quadruple N = (K, Σ, Δ, s).

• K, Σ, s are as before.

• Δ ⊆ K × Σ × (K ∪ {h, “yes”, “no”}) × Σ × {←, →, −} is a relation, not a function.b

– For each state-symbol combination (q, σ), there may be multiple valid next steps.

– Multiple lines of code may be applicable.

– But only one will be taken.

aRabin & Scott (1959).

b D95723006) on September 23,

(33)

### Nondeterminism (continued)

• As before, a program contains lines of code:

(q1, σ1, p1, ρ1, D1) ∈ Δ, (q2, σ2, p2, ρ2, D2) ∈ Δ,

...

(qn, σn, pn, ρn, Dn) ∈ Δ.

• But we cannot write

δ(qi, σi) = (pi, ρi, Di)

as in the deterministic case (p. 24) anymore.

(34)

### Nondeterminism (concluded)

• A conﬁguration yields another conﬁguration in one step if there exists a rule in Δ that makes this happen.

• There is only a single thread of computation.a

– Nondeterminism is not parallelism, multiprocessing, multithreading, or quantum computation.

aThanks to a lively discussion on September 22, 2015.

(35)

a

### (1931–)

aTuring Award (1976).

(36)

a

(37)

## K

(38)

### Decidability under Nondeterminism

• Let L be a language and N be an NTM.

• N decides L if for any x ∈ Σ, x ∈ L if and only if there is a sequence of valid conﬁgurations that ends in “yes.”

• In other words,

– If x ∈ L, then N(x) = “yes” for some computation path.

– If x ∈ L, then N(x) = “yes” for all computation paths.

(39)

### Decidability under Nondeterminism (continued)

• It is not required that the NTM halts in all computation paths.a

• If x ∈ L, no nondeterministic choices should lead to a

“yes” state.

• The key is the algorithm’s overall behavior not whether it gives a correct answer for each particular run.

• Note that determinism is a special case of nondeterminism.

aSo “accepts” may be a more proper term. Some books use “decides”

(40)

### Decidability under Nondeterminism (concluded)

• For example, suppose L is the set of primes.a

• Then we have the primality testing problem.

• An NTM N decides L if:

– If x is a prime, then N (x) = “yes” for some computation path.

– If x is not a prime, then N (x) = “yes” for all computation paths.

aContributed by Mr. Yu-Ming Lu (R06723032) on March 7, 2019.

(41)

### Complementing a TM’s Halting States

• Let M decide L, and M be M after “yes” ↔ “no”.

• If M is a deterministic TM, then M decides ¯L.

– So M and M decide languages that complement each other.

• But if M is an NTM, then M may not decide ¯L.

– It is possible that M and M accept the same input x (see next page).

– So M and M may accept languages that are not even disjoint.

(42)

(43)

### Time Complexity under Nondeterminism

• Nondeterministic machine N decides L in time f(n), where f : N → N, if

– N decides L, and

– for any x ∈ Σ, N does not have a computation path longer than f (| x |).

• We charge only the “depth” of the computation tree.

(44)

### Time Complexity Classes under Nondeterminism

• NTIME(f(n)) is the set of languages decided by NTMs within time f (n).

• NTIME(f(n)) is a complexity class.

(45)

### NP (“Nondeterministic Polynomial”)

• Deﬁne

NP =Δ 

k>0

NTIME(nk).

• Clearly P ⊆ NP.

• Think of NP as eﬃciently verifiable problems (see p.

333).

– Boolean satisﬁability (p. 119 and p. 194).

• The most important open problem in computer science is whether P = NP.

(46)

### Simulating Nondeterministic TMs

Nondeterminism does not add power to TMs.

Theorem 6 Suppose language L is decided by an NTM N in time f (n). Then it is decided by a 3-string deterministic TM M in time O(cf(n)), where c > 1 is some constant

depending on N .

• On input x, M goes down every computation path of N using depth-ﬁrst search.

– M does not need to know f (n).

– As N is time-bounded, the depth-ﬁrst search will not run indeﬁnitely.

(47)

### The Proof (concluded)

• If any path leads to “yes,” then M immediately enters the “yes” state.

• If none of the paths lead to “yes,” then M enters the

“no” state.

• The simulation takes time O(cf(n)) for some c > 1 because the computation tree has that many nodes.

Corollary 7 NTIME(f (n)))

c>1 TIME(cf(n)).a

aMr. Kai-Yuan Hou (B99201038, R03922014) on October 6, 2015:



c>1TIME(cf(n)) ⊆ NTIME(f(n)))?

(48)

### NTIME vs. TIME

• Does converting an NTM into a TM require exploring all computation paths of the NTM as done in Theorem 6 (p. 116)?

• This is a key question in theory with important practical implications.

(49)

### A Nondeterministic Algorithm for Satisfiability

φ is a boolean formula with n variables.

1: for i = 1, 2, . . . , n do

2: Guess xi ∈ { 0, 1 }; {Nondeterministic choices.}

3: end for

4: {Veriﬁcation:}

5: if φ(x1, x2, . . . , xn) = 1 then

6: “yes”;

7: else

8: “no”;

9: end if

(50)

### Computation Tree for Satisfiability

Ø\HVÙ

ØQRÙ ØQRÙØ\HVÙ Ø\HVÙ ØQRÙØQRÙØQRÙØ\HVÙ [ 

[  [  [ 

[ 

[  [  [ 

(51)

### Analysis

• The computation tree is a complete binary tree of depth n.

• Every computation path corresponds to a particular truth assignmenta out of 2n.

• Recall that φ is satisﬁable if and only if there is a truth assignment that satisﬁes φ.

aEquivalently, a sequence of nondeterministic choices.

(52)

### Analysis (concluded)

• The algorithm decides language

{ φ : φ is satisﬁable }.

– Suppose φ is satisﬁable.

∗ There is a truth assignment that satisﬁes φ.

∗ So there is a computation path that results in

“yes.”

– Suppose φ is not satisﬁable.

∗ That means every truth assignment makes φ false.

∗ So every computation path results in “no.”

(53)

### The Traveling Salesman Problem

• We are given n cities 1, 2, . . . , n and integer distance dij

between any two cities i and j.

• Assume dij = dji for convenience.

• The traveling salesman problem (tsp) asks for the total distance of the shortest tour of the cities.a

• The decision version tsp (d) asks if there is a tour with a total distance at most B, where B is an input.b

aEach city is visited exactly once.

bBoth problems are extremely important. They are equally hard (p. 404 and p. 502).

(54)

(55)

### A Nondeterministic Algorithm for tsp (d)

1: for i = 1, 2, . . . , n do

2: Guess xi ∈ { 1, 2, . . . , n }; {The ith city.}a

3: end for

4: {Verification:}

5: if x1, x2, . . . , xn are distinct and n−1

i=1 dxi,xi+1 ≤ B then

6: “yes”;

7: else

8: “no”;

9: end if

aCan be made into a series of log2 n binary choices for each xi so that the next-state count (2) is a constant, independent of input size.

Contributed by Mr. Chih-Duo Hong (R95922079) on September 27, 2006.

(56)

### Analysis

• Suppose the input graph contains at least one tour of the cities with a total distance at most B.

– Then there is a computation path for that tour.a – And it leads to “yes.”

• Suppose the input graph contains no tour of the cities with a total distance at most B.

– Then every computation path leads to “no.”

aIt does not mean the algorithm will follow that path. It just means such a computation path (i.e., a sequence of nondeterministic choices) exists.

(57)

### Remarks on the P = NP Open Problem

? a

• Many practical applications depend on answers to the P = NP question.?

• Veriﬁcation of password should be easy (so it is in NP).

– A computer should not take a long time to let a user log in.

• A password system should be hard to crack (loosely speaking, cracking it should not be in P).

• It took logicians 63 years to settle the Continuum Hypothesis; how long will it take for this one?

a B96902079, R00922018) on

(58)

### Nondeterministic Space Complexity Classes

• Let L be a language.

• Then

L ∈ NSPACE(f(n))

if there is an NTM with input and output that decides L and operates within space bound f (n).

• NSPACE(f(n)) is a set of languages.

• As in the linear speedup theorem,a constant coeﬃcients do not matter.

aTheorem 5 (p. 93).

In our learned space, we introduce a novel Projected Compatibil- ity Distance (PCD) function which is differentiable and en- sures diversity by aiming for at least one prototype to

Lingual thyroid is defined as an ectopic thyroid gland tissue located in the midline of the tongue base and it is uncommonly observed in clinical practice and is rare in children..

Histological sections showed tumor cells at a distance of 8 mm from the clinical and radiographic limit of the lesion, so the elimination of at least 1 cm of peripheral bone margin

It is better than the physical method because it considers the relative market values of the products generated by the joint cost when seeking to allocate it (which is a surrogate

Listen, point and repeat... Little EFL Phonics

Finally, I am going to learn how to play the flute, because I want to play a song for my daddy’s birthday this winter.. SPRING SUMMER FALL

By looking at the slope of the curve as t increases, we see that the rate of increase of the population is initially very small, then gets larger until it reaches a maximum at about

Root the MRCT b T at its centroid r. There are at most two subtrees which contain more than n/3 nodes. Let a and b be the lowest vertices with at least n/3 descendants. For such

Improper integrals can arise on bounded intervals. Suppose that f is continuous on the half-open interval [a, b) but is unbounded there..

One model for the growth of a population is based on the assumption that the population grows at a rate proportional to the size of the population.. That is a reasonable

Theorem (Comparison Theorem For Functions) Suppose that a ∈ R, that I is an open interval that contains a, and that f,g are real functions defined everywhere on I except possibly at

• Density is varying in the medium and the volume scattering properties at a point is the product of scattering properties at a point is the product of the density at that point

• Cell: A unit of main memory (typically 8 bits which is one byte).. – Most significant bit: the bit at the left (high- order) end of the conceptual row of bits in a

• Now suppose the settlement date for a bond selling at par (i.e., the quoted price is equal to the par value) falls between two coupon payment dates. • Then its yield to maturity

 Calculating the expected total edge number for one left path started at one problem with m’ edges.  Evaluating the total edge number for all right sub-problems #

• If a graph contains a triangle, any independent set can contain at most one node of the triangle.. • We consider graphs whose nodes can be partitioned into m

What was more surprising, when the sides of the two equilateral polygons changed at a certain rate, the pattern of the generated graph would become a tessellation.. Then we could

Q: Can we at least find the exact string theory background that gives our universe. A: A

Miroslav Fiedler, Praha, Algebraic connectivity of graphs, Czechoslovak Mathematical Journal 23 (98) 1973,

• A function is a piece of program code that accepts input arguments from the caller, and then returns output arguments to the caller.. • In MATLAB, the syntax of functions is

• If a graph contains a triangle, any independent set can contain at most one node of the triangle.. • We consider graphs whose nodes can be partitioned in m

Given a graph and a set of p sources, the problem of finding the minimum routing cost spanning tree (MRCT) is NP-hard for any constant p &gt; 1 .. When p = 1, i.e., there is only

For a 4-connected plane triangulation G with at least four exterior vertices, the size of the grid can be reduced to (n/2 − 1) × (n/2) , , which is optimal in the sense