TM Samples
TM Samples
TM
Example-1: Construct a TM for the language L = {0n1n2n} where n≥1
▪ Solution
▪ L = {0n1n2n | n≥1} represents language where we use only 3 characters, i.e., 0, 1 and 2.
▪ In this, some number of 0's followed by an equal number of 1's and then followed by an
equal number of 2's. Any type of string which falls in this category will be accepted by this
language.
▪ Suppose that our sample input is 001122. Here we have 2 0's, 2 1's and 2 2's
Turing Machine
TM
Example-1: Construct a TM for the language L = {0n1n2n} where n≥1
▪ Solution
▪ Step-1: Place the sample input (001122) into the tape.
X is used for blank
q0
Turing Machine
TM
Example-1: Construct a TM for the language L = {0n1n2n} where n≥1
▪ Solution
▪ Step-3: The move will be δ(q0, 0) = δ(q1, A, R) which means it will go to state q1, replaced 0 by A
and the head will move to the right as:
q1
▪ Step-4: The move will be δ(q1, 0) = δ(q1, 0, R) which means it will not change any symbol, remain
in the same state, and move to the right as:
q1
Turing Machine
TM
Example-1: Construct a TM for the language L = {0n1n2n} where n≥1
▪ Solution
▪ Step-5: The move will be δ(q1, 1) = δ(q2, B, R) which means it will go to state q2, replaced 1 by B,
and the head will move to the right as:
q2
▪ Step-6: The move will be δ(q2, 1) = δ(q2, 1, R) which means it will not change any symbol, remain
in the same state, and move to the right as:
q2
Turing Machine
TM
Example-1: Construct a TM for the language L = {0n1n2n} where n≥1
▪ Solution
▪ Step-7: The move will be δ(q2, 2) = δ(q3, C, R) which means it will go to state q3, replaced 2 by C
and the head will move to the right as:
q3
Turing Machine
TM
Example-1: Construct a TM for the language L = {0n1n2n} where n≥1
▪ Solution
▪ Step-8: If the head goes to the right, it will meet the blank (X), therefore, firstly the first 0 on the left
will be checked and replaced by the TM.
▪ Now move δ(q3, 2) = δ(q3, 2, L) and δ(q3, C) = δ(q3, C, L) and δ(q3, 1) = δ(q3, 1, L) and δ(q3, B) =
δ(q3, B, L) and δ(q3, 0) = δ(q3, 0, L), and then move δ(q3, A) = δ(q0, A, R), it means will go to state
q0, replaced A by A and head will move to the right as:
q0
Turing Machine
TM
Example-1: Construct a TM for the language L = {0n1n2n} where n≥1
▪ Solution
▪ Step-9: The move will be δ(q0, 0) = δ(q1, A, R) which means it will go to state q1, replaced 0 by A,
and the head will move to the right as:
q1
Turing Machine
TM
Example-1: Construct a TM for the language L = {0n1n2n} where n≥1
▪ Solution
▪ Step-10: The move will be δ(q1, B) = δ(q1, B, R) which means it will not change any symbol, remain
in the same state and move to the right as:
q1
Turing Machine
TM
Example-1: Construct a TM for the language L = {0n1n2n} where n≥1
▪ Solution
▪ Step-11: The move will be δ(q2, C) = δ(q2, C, R) which means it will not change any symbol, remain
in the same state and move to the right as:
q2
Turing Machine
TM
Example-1: Construct a TM for the language L = {0n1n2n} where n≥1
▪ Solution
▪ Step-12: The move will be δ(q2, 2) = δ(q3, C, L) which means it will go to state q3, replaced 2 by C,
and the head will move to the left until we reach A as:
q3
Turing Machine
TM
Example-1: Construct a TM for the language L = {0n1n2n} where n≥1
▪ Solution
▪ Step-13: Immediately before B is A that means all the 0's are marked by A. So, we will move right to
ensure that no 1 or 2 is present. The move will be δ(q2, B) = (q4, B, R) which means it will go to state
q4, will not change any symbol, and move to the right as:
q4
Turing Machine
TM
Example-1: Construct a TM for the language L = {0n1n2n} where n≥1
▪ Solution
▪ Step-14: The move will be (q4, B) = δ(q4, B, R) and (q4, C) = δ(q4, C, R) which means it will not
change any symbol, remain in the same state and move to the right as:
q4
Turing Machine
TM
Example-1: Construct a TM for the language L = {0n1n2n} where n≥1
▪ Solution
▪ Step-15: The move δ(q4, X) = (q5, X, R) which means it will go to state q5 which is the HALT state
and HALT state is always an accept state for any TM. X is used for blank.
q5
Turing Machine
TM
Example-1: Construct a TM for the language L = {0n1n2n} where n≥1
▪ Solution
Turing Machine
TM
Example-2: Given the following TM for the language L = {0n1n2n} where n≥1. Using state diagram,
trace for the input: 001122, and write down your step-by-step solution on the right of the given
state diagram. 001122 A0B1C2 AABBC2
Solution A01122 A0B1C2 AABBC2
A01122 A0B1C2 AABBCC
A01122 A0B1C2 AABBCCX
A0B122 A0B1C2 AABBCC Accepted
A0B122 A0B1C2
A0B122 AAB1C2
A0B1C2 AAB1C2
A0B1C2 AABBC2
THANKS FOR
YOUR ATTENTION & ATTENDANCE