Turing Machine and PDA Notes PDF
Turing Machine and PDA Notes PDF
A Turing Machine (TM) is a mathematical model which consists of an infinite length tape divided into cells
on which input is given. It consists of a head which reads the input tape. A state register stores the state
of the Turing machine. After reading an input symbol, it is replaced with another symbol, its internal state
is changed, and it moves from one cell to the right or left. If the TM reaches the final state, the input
string is accepted, otherwise rejected.
q0= {q0}
B = blank symbol
F = {qf }
δ is given by:
Here the transition 1Rq1 implies that the write symbol is 1, the tape moves right, and the next state is q 1.
Similarly, the transition 1Lq2 implies that the write symbol is 1, the tape moves left, and the next state is
q2.
2. Explain the different types of Turing Machines
A) Multi-tape Turing Machines have multiple tapes where each tape is accessed with
a separate head. Each head can move independently of the other heads. Initially the input is on tape 1
and others are blank. At first, the first tape is occupied by the input and the other tapes are kept blank.
Next, the machine reads consecutive symbols under its heads and the TM prints a symbol on each tape
and moves its heads.
A Multi-tape Turing machine can be formally described as a 6-tuple (Q, X, B, δ, q0, F) where:
B) Multi-track Turing machines, a specific type of Multi-tape Turing machine, contain multiple tracks
but just one tape head reads and writes on all tracks. Here, a single tape head reads n symbols from n
tracks at one step. It accepts recursively enumerable languages like a normal single-track single-tape
Turing Machine accepts.
A Multi-track Turing machine can be formally described as a 6-tuple (Q, X, Σ, δ, q0, F) where:
δ(Qi, [a1, a2, a3,....]) = (Qj, [b1, b2, b3,....], Left_shift or Right_shift)
Note: For every single-track Turing Machine S, there is an equivalent multi-track Turing Machine M
such that L(S) = L(M).
D) A semi-infinite tape Turing Machine - A Turing Machine with a semi-infinite tape has a left end but
no right end. The left end is limited with an end marker.
It is a two-track tape:
1. Upper track: It represents the cells to the right of the initial head position.
2. Lower track: It represents the cells to the left of the initial head position in reverse order.
The infinite length input string is initially written on the tape in contiguous tape cells.
The machine starts from the initial state q0 and the head scans from the left end marker ‘End’. In each
step, it reads the symbol on the tape under its head. It writes a new symbol on that tape cell and then it
moves the head either into left or right one tape cell. A transition function determines the actions to be
taken.
It has two special states called accept state and reject state. If at any point of time it enters into the
accepted state, the input is accepted and if it enters into the reject state, the input is rejected by the TM.
Example:
Problem: Does the Turing machine finish computing of the string w in a finite number of steps? The
answer must be either yes or no.
Proof: At first, we will assume that such a Turing machine exists to solve this problem and then we will
show it is contradicting itself. We will call this Turing machine as a Halting machine that produces a ‘yes’
or ‘no’ in a finite amount of time. If the halting machine finishes in a finite amount of time, the output
comes as ‘yes’, otherwise as ‘no’. The following is the block diagram of a Halting machine:
Infinite loop
Yes
Qi Qj
Input Halting
string Machine
No
The Post Correspondence Problem (PCP), introduced by Emil Post in 1946, is an undecidable decision
problem. The PCP problem over an alphabet is stated as follows:
Solution
x1 x2 x3
M Abb aa aaa
N Bba aaa aa
Here,
x2 x1x3 = ‘aaabbaaa’
x2 x1x3 = y2y1 y3
Example 2
Find whether the lists M = (ab, bab, bbaaa) and N = (a, ba, bab) have a Post Correspondence
Solution?
Solution
x1 x2 x3
M ab bab bbaaa
N a ba bab
Here,
Example:
Grammar G2:
Here,
Recursively enumerable
Type 0 Unrestricted grammar Turing machine
Language
Context-sensitive Linear-bounded
Type 1 Context-sensitive grammar
Language automaton
Pushdown
Type 2 Context-free grammar Context-free language
automaton
Finite state
Type 3 Regular grammar Regular language
automaton
Type - 3 Grammar
Type-3 grammars generate regular languages. Type-3 grammars must have a single non-terminal on
the left-hand side and a right-hand side consisting of a single terminal or single terminal followed by a
single non-terminal.
The productions must be in the form X → a or X → aY where X, Y ∈ N
(Non terminal)
And a ∈ T (Terminal)
The rule S → ε is allowed if S does not appear on the right side of any rule.
Example
X → ε
X → a | aY
Y →b
Type - 2 Grammar
Type-2 grammars generate context-free languages.
Example
S → X a
X → a
X → aX
X → abc
X → ε
Type - 1 Grammar
Type-1 grammars generate context-sensitive languages. The productions must be in the form
αAβ→αγβ
where A ∈ N (Non-terminal)
The rule S → ε is allowed if S does not appear on the right side of any rule. The languages generated by
these grammars are recognized by a linear bounded automaton.
Example
AB → AbBc
A → bcA
B → b
Type - 0 Grammar
Type-0 grammars generate recursively enumerable languages. The productions have no restrictions.
They are any phase structure grammar including all formal grammars.
The productions can be in the form of α→ β where α is a string of terminals and non-terminals with at
least one non-terminal and α cannot be null. β is a string of terminals and non-terminals.
Example
S → ACaB
Bc → acB
CB → DB
aD → Db
an input tape,
a control unit, and
a stack with infinite size.
The stack head scans the top symbol of the stack.
A PDA may or may not read an input symbol, but it has to read the top of the stack in every transition.
Takes
Input Finite control
unit Accept or reject
Push or Pop
Input tape
Stack
The following diagram shows a transition in a PDA from a state q 1 to state q2, labeled as a,b → c :
Push
Input Stack top
Symbol
Symbol Symbol
a,b→c
q q
This means at state q1, if we encounter an input string ‘a’ and top symbol of the stack is ‘b’, then we pop
‘b’, push ‘c’ on top of the stack and move to state q2.
9. Define Instantaneous Description
The instantaneous description (ID) of a PDA is represented by a triplet (q, w, s) where
q is the state
w is unconsumed input
s is the stack contents
A → a
A → BC
S → ϵ
Step 2 Remove Null productions. (Using the Null production removal algorithm discussed earlier)
Step 3 Remove unit productions. (Using the Unit production removal algorithm discussed earlier)
Step 4 Replace each production A → B1…Bn where n > 2 with A → B1C where C → B2 …Bn. Repeat
this step for all productions having two or more symbols in the right side.
Step 5 If the right side of any production is in the form A→ aB where a is a terminal and A, B are non-
terminal, then the production is replaced by A→ XB and X→ a. Repeat this step for every
production which is in the form A→ aB.
Problem:
Convert the following CFG into CNF
Solution:
(1) Since S appears in R.H.S, we add a new state S0 and S0→S is added to the production set and it
becomes:
S0→S, S→ ASA | aB | a, A → B | S | ϵ, B → b
S0→S, S→ ASA | aB | a | AS | SA | S, A → B | S, B → b
(3) Now we will remove the unit productions. After removing S→ S,
A → B | S, B→b
A→S|b
B→b
A → b |ASA | aB | a | AS | SA, B → b
(4) Now we will find out more than two variables in the R.H.S
Hence we will apply step 4 and step 5 to get the following final production set which is in
CNF:
S0→ AX | aB | a | AS | SA
S→ AX | aB | a | AS | SA
A → b |AX | aB | a | AS | SA
B→b
X→ SA
(5) We have to change the productions S0→ aB, S→ aB, A→ aB And the final production set becomes:
S0→ AX | YB | a | AS | SA S→ AX | YB | a | AS | SA
A → b |AX | YB | a | AS | SA B → b
X→ SA Y → a
A→b
A → bD1…Dn
S→ϵ
Step 2 Remove Null productions. (Using the Null production removal algorithm discussed earlier)
Step 3 Remove unit productions. (Using the Unit production removal algorithm discussed earlier)
Step 5 Do proper substitutions of productions to convert it into the proper form of GNF.
Problem:
Convert the following CFG into CNF
S→ XY | Xn | p
X → mX | m
Y → Xn | o
Solution:
Here, S does not appear on the right side of any production and there are no unit or null productions in
the production rule set. So, we can skip Step 1 to Step 3.
Step 4:
X in S → XY | Xo | p
with
mX | m
we obtain
S → mXY | mY | mXo | mo | p.
X in Y→ Xn | o
X → mX | m
we obtain
Y→ mXn | mn | o.
Two new productions O→ o and P → p are added to the production set and then we came to the final GNF
as the following:
S → mXY | mY | mXC | mC | p
X→ mX | m
Y→ mXD | mD | o
O→o
P→p
L (G) = L (P)
Step 3 The start symbol of CFG will be the start symbol in the PDA.
Step 4 All non-terminals of the CFG will be the stack symbols of the PDA and all the terminals of
the CFG will be the input symbols of the PDA.
Step 5 For each production in the form A→ aX where a is terminal and A, X are combination of
terminal and non-terminals, make a transition δ (q, a, A).
Problem
Construct a PDA from the following CFG.
S → XS | , A → aXb | Ab | ab
Solution
where δ:
δ δ(q, a, a) = {(q, )}
δ δ(q, 1, 1) = {(q, )}