CPSC 313 - A Nondeterministic Turing Machine

advertisement
CPSC 313 — Winter, 2005
A Nondeterministic Turing Machine
In this document we will consider a nondeterministic Turing machine that decides the following language.
L = {ww | w ∈ {a, b}∗ }
This Turing machine implements an algorithm that repeatedly passes to the right and then back to the
right over the non-blank portion of its tape, until the input string is either accepted or rejected. The
behaviour of the machine on input x ∈ {a, b}∗ is as follows.
A guess is made during the first pass, which carries out the following.
if x = ² then
accept
else
Erase and remember the leftmost symbol, α ∈ {a, b}∗ , that appears on the non-blank
portion of the tape.
Sweep to the right. At some point, guess that another copy of the symbol α begins the
second half of x. Replace this copy of α with a “#” and move back to the left end of the
non-blank portion of the tape (to begin the next pass).
If the end of the non-blank portion of the tape is reached (and a B is found) before a guess
has been made, then reject.
end if
Note that if the algorithm has not already halted then there is still at least one non-blank symbol on
the tape at the end of this first pass. In particular, the tape includes at least one “#.”
1
Each of the remaining passes is deterministic. These carry out the following process.
if the non-blank portion begins with an a or a b then
Erase and remember the leftmost non-blank symbol, α, that is on the tape.
Sweep over any a’s and b’s that are to the right, until a # is seen.
Sweep over any other #’s until some different symbol, β ∈ {a, b, B}, is found.
if α = β then
Replace β with a “#” and move back to the left end of the non-blank part of the
tape (in order to begin the next pass).
else
reject
end if
else (the non-blank part of the tape begins with #)
Sweep over all #’s until a symbol γ ∈ {a, b, B} is found.
if γ = B then
accept
else
reject
end if
end if
The transition diagram for a nondeterministic Turing machine M that implements this algorithm is
shown on the next page.
The first pass (described on the previous page) is implemented using states q0 , q² , [q1 , a], [q1 , b], q2 , and
the transition from q2 to q3 .
Notice that there are multiple transitions defined for the state [q1 , a] and the symbol a, as well as the
state [q1 , b] and the symbol b. The guess that identifies the second part of the input string (that is
described on the previous page) is carried out by using the transitions, in this set, that move to state q 2
instead of staying in state [q1 , a] or [q1 , b].
The later passes are implemented using states q3 , [q4 , a], [q5 , a], [q4 , b], [q5 , b] and q6 (which are used
while non-blank symbols to the left of the first # must be processed), as well as states q 7 and qa (which
are used to implement a pass that begins with the discovery that the leftmost non-blank symbol is #).
2
a/a, →
b/b, →
[q1 , a]
Start
a/B, →
a/#, ←
a/a, →
b/b, →
a/a, ←
b/b, ←
[q5 , a]
#/#, →
a/B, →
q2
q0
q3
B/B, →
a/a, ←
b/b, ←
#/#, ←
a/#, ←
q6
B/B, →
b/B, →
b/#, ←
b/B, →
b/#, ←
#/#, →
#/#, →
[q1 , b]
B/B, →
[q4 , a]
#/#, →
[q4 , b]
[q5 , b]
#/#, →
q²
a/a, →
b/b, →
q7
a/a, →
b/b, →
#/#, →
B/B, →
qa
If a language is decided by a nondeterministic Turing machine then there exists a deterministic Turing
machine that decides the same language, as well; a simulation of a nondeterministic Turing machine by
a deterministic Turing machine has been described in class and in the textbook.
Unfortunately, the number of steps needed to simulate a nondeterministic device that halts after t steps
is, in the worst case, exponential in t: The deterministic simulation generates the first t levels of a
computation tree in order to carry out this simulation, and the number of nodes in the tree that must
be considered in order to do this is exponential in t in the worst case. No (significantly) faster simulation
of a nondeterministic Turing machine by a deterministic one is currently known.
On the other hand, there is a deterministic Turing machine that decides the above language, L, without
using significantly more steps. To be more precise, if a given string has length n, then the computation
tree of the above Turing machine has depth in O(n2 ), so no single computation of M on the string has
length that is more than quadratic in n. A deterministic (one-tape) Turing machine that decides the
above language using a quadratic number of steps also exists.
Exercise: Describe this machine!
Hint: One way to do this is to describe a new initial stage of the algorithm that uses a quadratic number
of steps to detect the midpoint of the input string in a deterministic way.
3
Download