The Theory of Computation

Bernard M.E. Moret

Addison-Wesley-Longman, 1998


Detailed Solutions

Chapter 3, Problem 32




The trick here is mostly in figuring out a way to pace the submachine that will handle the substring z, since that substring is half the length of the input. The submachine for z must make only one transition for every two transitions made by the submachine for substring x, which dictates the pace (since it is fed the real input). One solution is to use a toggle: on even positions in x, the submachine for z makes a transition, but on odd ones it does not. Otherwise, the machine is constructed exactly along the lines discussed in class for this class of languages: a state of the NFA we are building will be a 7-tuple, augmented into an 8-tuple by the odd/even toggle. The 7-tuple members include 4 current states for the 4 submachines handling the 4 substrings and 3 markers that store the initial guesses for the starting positions of the 2nd, 3rd, and 4th submachines. (Note that the 1st and 3rd submachines must be kept separate: they have exactly the same transition function, but need not start in the same state and thus need separate current states.)

So, given a DFA M=(Sigma,Q,S,F,delta) for L, we construct an NFA M'=(Sigma,Q',S',F',delta') for L' as follows.

  • Q' = {S'} union {(qi,qj,qk,ql,qm,qn,qo,t) | qi,qj,qk,ql,qm,qn,qo in Q and in {odd,even}}
  • delta'(S',epsilon) = {(S,qi,qi,qj,qj,qk,qk,even) | qi,qj,qk in Q}
  • delta'((qi,qj,qk,ql,qm,qn,qo,even),a) = {(qi',qj,qk',ql,qm',qn,qo,odd) | delta(qi,a)=qi', delta(qm,a)=qm', and there exist alpha and beta such that delta(delta(qk,alpha),beta)=qk'}
  • delta'((qi,qj,qk,ql,qm,qn,qo,odd),a) = {(qi',qj,qk',ql,qm',qn,qo',even) | delta(qi,a)=qi', delta(qm,a)=qm', there exist alpha and beta such that delta(delta(qk,alpha),beta)=qk', and there exists gamma such that delta(qo,gamma)=qo'}
  • F'={(qi,qi,qj,qj,qk,qk,q,even) | qi,qj,qk in Q and q in F}
  • In order to accept, we must be in an "even" state, i.e., we must have seen an even number of input characters; the transition function keeps toggling between odd and even state labels and the submachine for z only makes transitions when we read an even-numbered input character.