HW6Sols PDF
HW6Sols PDF
HW6Sols PDF
Homework 6 Solutions
November 10, 2015 Timothy Johnson
Symbol
State 0 1 X Y B
q0 (q1 , X, R) - - (q3 , Y, R) -
q1 (q1 , 0, R) (q2 , Y, L) - (q1 , Y, R) -
q2 (q2 , 0, L) - (q0 X, R) (q2 , Y, L) -
q3 - - - (q3 , Y, R) (q4 , B, R)
q4 - - - - -
1
q0 000111 ` Xq1 00111
` X0q1 0111
` X00q1 111
` X0q2 0Y 11
` Xq2 00Y 11
` q2 X00Y 11
` Xq0 00Y 11
` XXq1 0Y 11
` XX0q1 Y 11
` XX0Y q1 11
` XX0q2 Y Y 1
` XXq2 0Y Y 1
` Xq2 X0Y Y 1
` XXq0 0Y Y 1
` XXXq1 Y Y 1
` XXXY q1 Y 1
` XXXY Y q1 1
` XXXY q2 Y Y
` XXXq2 Y Y Y
` XXq2 XY Y Y
` XXXq0 Y Y Y
` XXXY q3 Y Y
` XXXY Y q3 Y
` XXXY Y Y q3 B
` XXXY Y Y Bq4 B
We cross off the first character in the string. (If the input is empty, we accept, because this
is in our language when w = .) Then we scan to the end of the string and check if the last
character matches the first one.
If it does not match, the machine crashes. If it does match, we cross it off and return to the
beginning to check the second character of the string. We repeat until every character has
been crossed off, at which point we accept.
2
Our transition function is defined as follows, where q6 is the final state:
Symbol
State 0 1 X Y B
q0 (q1 , X, R) (q2 , X, R) - - (q6 , B, R)
q1 (q1 , 0, R) (q1 , 1, R) - - (q3 , B, L)
q2 (q2 , 0, R) (q2 , 1, R) - - (q4 , B, L)
q3 (q5 , Y, L) - - - -
q4 - (q5 , Y, L) - - -
q5 (q5 , 0, L) (q5 , 1, L) (q0 , X, R) - -
q6 - - - - -
First we scan to the end of our input. Then if we see a 0, we change it to 1. If we see a 1, we
change it to 0, and carry to the next digit. Eventually either we will reach a zero, or we will
reach the $ at the beginning.
If we reach a zero, we change it to 1 and stop. If we reach the $ at the beginning, we change
it to 1 and stop.
Our transition function is as follows, where q2 is the final state:
Symbol
State 0 1 $ B
q0 (q0 , 0, R) (q0 , 1, R) (q0 , $, R) (q1 , B, L)
q1 (q2 , 1, R) (q1 , 0, L) (q2 , 1, R) -
q2 - - - -
We can do either a breadth-first or depth-first search to find all of the reachable ID’s. I choose
to do a breadth-first search, which gives us the ID’s in the following order:
3
• q0 011
• 1q0 11
• 10q1 1
• 101q1 B
• 1q0 01
• 101Bq2 B
• 11q0 1
• 110q1 B
• 110Bq2 B
We will scan from left to right on our first tape. In state q1 , the position on the second tape
stores the number of extra 0’s we have seen. In state q2 , the position on the second tape
stores the number of extra 1’s we have seen. State q3 is our final state.
We begin by writing an extra $ symbol on the second tape, to mark when it is empty. We
know we have read all of our input when we reach a blank symbol on the first tape.
Our transition function is as follows.
δ 0,B 1,B B,B 0,$ 1,$ B,$
q0 (q1 , B, R, $, R) (q2 , B, R, $, R) (q3 , B, R, $, R) - - -
q1 (q1 , B, R, B, R) (q1 , B, R, B, L) - (q1 , B, R, $, R) (q2 , B, R, $, R) (q3 , B, R, $, R)
q2 (q2 , B, R, B, L) (q2 , B, R, B, R) - (q1 , B, R, $, R) (q2 , B, R, $, R) (q3 , B, R, $, R)
q3 - - - - - -