0% found this document useful (0 votes)
4 views

Turing Machine Part 2 Example (2) (3)

Uploaded by

aboodokasheh282
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Turing Machine Part 2 Example (2) (3)

Uploaded by

aboodokasheh282
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Turing Machine Examples

Turing machine for anbncn | n ≥ 1

Previously we have seen example of turing machine for anbn | n ≥ 1


We will use the same concept for anbncn | n ≥ 1 also.
Approach for anbncn | n ≥ 1

1.Mark 'a' then move right.


2.Mark 'b' then move right
3.Mark 'c' then move left
4.Come to far left till we get 'X'
5.Repeat above steps till all 'a', 'b' and 'c' are marked
6.At last if everything is marked that means string is
accepted.
Explanation of TAPE movement
1.Step 1-2
Input is given as "aaabbbccc" (scan string from left to right)
2.Mark 'a' as 'X' and move one step right
3.Reach unmarked 'b' and pass every 'a' and 'Y'(in case) on the way to 'b'

1.Step 3-4
Mark 'b' as 'Y' and move one step right
2.Reach unmarked 'c' and pass every 'b' and 'Z'(in case) on the way to 'c'
3.Mark 'c' as 'Z' and move one step left cause now we have to repeat
process
4.Reach unmarked 'X' and pass every 'Z', 'b', 'Y', 'a' on the way to 'X'
5.Move to 'a' and repeat the process
1.Step 5-9
Step 1-4 are repeated
2.Step 10
When TAPE header reaches 'X' and next symbol is 'Y' that means 'a's are finished
3.Check for 'b's and 'c's by going till BLANK(in right) and passing 'Y' and 'Z' on the
way
4.If no 'b' and 'c' are not found that means string is accepted

State Transition Diagram


1.We have designed state transition diagram for anbncn | n ≥ 1 as follows:
Following Steps:
a. Mark 'a' with 'X' and move towards unmarked 'b'
b. Move towards unmarked 'b' by passing all 'a's
c. To move towards unmarked 'b' also pass all 'Y's if exist
Following Steps:
a. Mark 'b' with 'Y' and move towards unmarked 'c'
b. Move towards unmarked 'c' by passing all 'b's
c. To move towards unmarked 'c' also pass all 'Z's if exist
Following Steps:
a. Mark 'c' with 'Z' and move towards first 'X' (in left)
b. Move towards first 'X' by passing all 'Z's, 'b's, 'Y's and 'a's
c. When 'X' is reached just move one step right by doing nothing
To check all the 'a's, 'b's and 'c's are over add loops for checking 'Y' and 'Z'
after "we get 'X' followed by 'Y'"
To reach final state(qf) just replace BLANK with BLANK and move either
direction
Turing Machine to check whether given string is Even Palindrome
or not

A string w is called palindrome if reading w from left to right gives the same result as
reading w from right to left. An even palindrome has even number of symbols.
Basic Idea :

The tape head reads the leftmost symbol of w, deletes this symbol and “remembers” it by means of
a state. Then the tape head moves to rightmost symbol and tests whether it is equal to the (already
deleted) leftmost symbol.

If they are equal, then the rightmost symbol is deleted, the tape head moves to the new leftmost
symbol, and the whole process is repeated . Else the machine can’t reach the final state and the
string will be rejected.

Meanings of symbols used for solving problem:


R, L – direction of movement of one unit on either side .
B-Blank
a, b-symbols whose combination string is to be tested
Step-1:
We start with Q0 state if we get a symbol “a” as input then there should also be “a” at the ending
of the string then only the string is palindrome and we must verify that. We first make the current
input “a” to B blank and go to state Q1 move rightwards to traverse the string till we reach the
end. Keep the input symbols a or b whichever comes in ways should be remain unchanged.

We can reach the end of the string when we get Blank as the input symbol then we change state
to Q2 and test if the previous symbol is “a” then we change to state Q3 and then only we will
replace it by Blank and we have successfully tested that string is palindrome till this point now we
will traverse back or leftwards (keeping a and b unchanged which comes in way) on the string and
till we get Blank which is the symbol which we made Blank at the start and we change state to
Q0.Now we repeat the same procedure for “b” as input.
Step-3:
If the string was palindrome then there will be only Blank symbol left and hence we test it at Q0 if
we get blank hence the string gets accepted and is palindrome, at this point there is one more
condition is included which is of null string or empty string is palindrome should be accepted
Construct a Turing machine for L = {aibjck | i*j = k; i, j, k ≥ 1}
Solution:
1. First scan the string from left to right to verify that it is of form a+b+c+;
if it is scan to start of tape* and if not, reject. Easy to do with finite
control/FA.
2. Cross off the first a and scan until the first b occurs. Shuttle between
b’s and c’s crossing off one of each until all b’s are gone. If all c’s have
been crossed off and some b’s remain, reject.
3. Restore** the crossed off b’s and repeat step 2 if there are a’s
remaining. If all a’s gone, check if all c’s are crossed off; if so, accept;
else reject.
Turing machine for M1 that accepts strings of {w#w|w ∈ {0, 1}
∗}.
Turing machine for M1 that accepts strings of {w#w|w ∈ {0, 1}
∗}.

It works as follows:
1. Scan the input to be sure that it contains a single # symbol. If not, reject.
2. Zig-zag across the tape to corresponding positions on either side of the # symbol to
check whether these positions contain the same symbol. If they do not, reject.
Cross off symbols as they are checked.
3. When all symbols to the left of # have been crossed off, check for any remaining
symbols to the right of the #. If any symbols remain, reject; otherwise, accept.
Turing machine for M1 that accepts strings of {w#w|w ∈ {0, 1} ∗}.

You might also like