Unit-3 ATCD
Unit-3 ATCD
Pushdown automata
Turing Machine
Contents
• Pushdown automata: Definition, model,
acceptance of CFL, introduction to
Deterministic PDA and Non-Deterministic PDA,
design of PDA.
• Turing Machine: Turing Machine, definition,
model, design of TM, recursively enumerable
languages.
Pushdown automata: Definition
• Pushdown automata is a way to implement a CFG in the same way we design
DFA for a regular grammar.
• A DFA can remember a finite amount of information, but a PDA can remember
an infinite amount of information.
• A pushdown automaton (PDA) is a computational model that recognizes
context-free languages.
• It consists of an input tape, a stack, and a finite set of states.
• A pushdown automaton (PDA) is a finite automaton equipped with a stack-
based memory.
• Each transition
– is based on the current input symbol and the top of the stack,
– optionally pops the top of the stack, and
– optionally pushes new symbols onto the stack.
• Initially, the stack holds a special symbol Z0 that indicates the bottom of the
stack.
Instantaneous Description (ID)
• Instantaneous Description (ID) is an informal notation of how a PDA
“computes” an input string and makes a decision whether that string is
accepted or rejected.
• An ID is a triple (q, w, α), where:
1. q is the current state.
2. w is the remaining input.
3.α is the stack contents, top at the left.
• Turnstile Notation
• ⊢ sign is called a “turnstile notation” and represents
one move.
⊢* sign represents a sequence of moves.
Eg- (p, b, T) ⊢ (q, w, α)
This implies that while taking a transition from state p to state q, the input
symbol ‘b’ is consumed, and the top of the stack ‘T’ is replaced by a new
string ‘α’
Model
• A PDA may or may not read an input symbol, but it has to read the top of the stack in every
transition.
• PDA Components:
• 1.Input tape: The input tape is divided in many cells or symbols. The input head is read-only
and may only move from left to right, one symbol at a time.
• 2.Finite control: The finite control has some pointer which points the current symbol which is
to be read.
• 3. Stack: The stack is a structure in which we can push and remove the items from one end
only. It has an infinite size. In PDA, the stack is used to store the items temporarily.
Pushdown automata: Definition
A PDA can be formally described as a 7-tuple (Q, ∑, Γ,δ, q0, Z0,F) −
• Q is the finite number of states
• ∑ is input alphabet
• Γ is stack symbols
• δ is the transition function: Q × (∑ ∪ {ε}) × Γ Q × Γ*
• q0 is the initial state (q0 ∈ Q)
• Z0 is the initial stack top symbol (Γ ∈ S)
• F is a set of accepting states (F ∈ Q)
• The following diagram shows a transition in a PDA from a state q1 to state q2, labeled
as a,b → c −
• 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.
Acceptance of CFL
• There are two different ways to define PDA acceptability.
Final State Acceptability
• In final state acceptability, a PDA accepts a string when, after reading the entire
string, the PDA is in a final state. From the starting state, we can make moves
that end up in a final state with any stack values. The stack values are irrelevant
as long as we end up in a final state.
• For a PDA (Q, ∑, Γ, δ, q0, Z0, F), the language accepted by the set of final states F
is −
• L(PDA) = {w | (q0, w, Z0) ⊢* (q, ε, x), q ∈ F} for any input stack string x.
Empty Stack Acceptability
• Here a PDA accepts a string when, after reading the entire string, the PDA has
emptied its stack.
• For a PDA (Q, ∑, S, δ, q0, Z0, F), the language accepted by the empty stack is −
• L(PDA) = {w | (q0, w, I) ⊢* (q, ε, ε), q ∈ Q}
Example
• Construct a PDA that accepts L = {0n 1n | n ≥ 0}
Solution
• Final State Acceptability:
• This language accepts L = {ε, 01, 0011, 000111, ............................. } Here, in this example, the
number of ‘a’ and ‘b’ have to be same.
• Initially we put a special symbol ‘$’ into the empty
stack.
• Then at state q2, if we encounter input 0 and top is
Null, we push 0 into stack. This may iterate. And if
we encounter input 1 and top is 0, we pop this 0.
• Then at state q3, if we encounter input 1 and top is
0, we pop this 0. This may also iterate. And if we
encounter input 1 and top is 0, we pop the top
element.
• If the special symbol ‘$’ is encountered at top of the
stack, it is popped out and it finally goes to the
accepting state q4.
Example
The language accepted by DPDA is a subset of The language accepted by NPDA is not a
the language accepted by NPDA. subset of the language accepted by DPDA.
The language accepted by DPDA is called The language accepted by NPDA is called
DCFL(Deterministic Context-free Language) NCFL(Non-deterministic Context-free
which is a subset of NCFL(Non-deterministic Language).
Context-free Language) accepted by NPDA.
There is only one state transition from one There may or may not be more than one state
state to another state for an input symbol. transition from one state to another state for
same input symbol.
Turing Machine
• A Turing machine is a computational model, like Finite Automata (FA),
Pushdown automata (PDA), which works on unrestricted grammar. The Turing
machine is the most powerful computation model when compared with FA and PDA.
• Formal Definition of Turing machine M can be defined as follows −
• M = (Q, ∑, Γ,δ, q0, Z0,F)
where
• Q represents the finite, non-empty set of states.
• Γ represents the set of tape alphabets.
• ∑ represents the non-empty set of input alphabets.
• δ is the transition function, whose mapping is given as, δ : Q x Γ → Q x Γ x {Left_shift,
Right_shift}.
• q0 is the initial state of the machine
• B is the blank symbol
• F is the set of final states or halt states.
•
Turing Machine
• A single tape Turing machine has a single infinite tape, which is divided into cells.
• The tape symbols are present in these cells.
• →A finite control is present, which controls the working of Turing machines based on the given input.
• →The Finite control has a Read/write head, which points to a cell in tape.
• →A Turing machine can move both left and right from one cell to another.
• 2. The finite control and the tape head which is responsible for reading the current input
symbol. The tape head can move to left to right.
• 3. A finite set of states through which machine has to undergo.
• 4. Finite set of symbols called external symbols which are used in building the logic of Turing
machine.
Design of TM Example
• Construct a Turing Machine (TM) for the language L = {0ⁿ1ⁿ | n ≥ 1}, which accepts strings of
equal 0s followed by equal 1s.
• Components:
• Q = {q₀, q₁, q₂, q₃} (q₀ is the initial state)
• T = {0,1,X,Y,B} (B represents blank, X and Y mark processed symbols)
• Σ = {0,1} (input symbols)
• F = {q₃} (final state)
• Transition Table:
• Let us see how this turing machine works for 0011. Initially head points to 0 which is
underlined and state is q0 as:
B 0 0 1 1 B
• The move will be δ(q0, 0) = (q1, X, R). It means, it will go to state q1, replace 0 by X and head
will move to right as:
B X 0 1 1 B
• The move will be δ(q1, 0) = (q1, 0, R) which means it will remain in same state and without
changing any symbol, it will move to right as:
B X 0 1 1 B
• The move will be δ(q1, 1) = (q2, Y, L) which means it will move to q2 state and changing 1 to Y,
it will move to left as:
B X 0 Y 1 B
• Working on it in the same way, the machine will reach state q3 and head will point to B as
shown:
B X X Y Y B
State a b X Y B
q0 (q1, X, R) (q3, Y , R)
q1 (q1, a, R) (q1, Y, L) (q1, Y, R)
q2 (q2, a , L) (q0, X , R)
q3 (q3, Y , R) = (q4, B
, R/L)
q4 Halt
Transition Functions:
δ(q0, a) = (q1, X, R)
δ(q1, a) = (q1, a, R)
δ(q1, Y) = (q1, Y, R)
δ(q1, b) = (q2, Y, R)
δ(q2, b) = (q2, b , R)
δ(q2, Z) = (q2, Z , R)
δ(q2, c) = (q3, Z , L)
δ(q2, c) = (q3, Z , L)
δ(q3, a) = (q3, a , L)
δ(q3, b) = (q3, b , L)
δ(q3, Y) = (q3, Y , L)
δ(q3, Z) = (q3, Z , L)
δ(q3, X) = (q0, X , R)
δ(q0, Y) = (q4, Y , R)
δ(q4, Y) = (q4, Y , R)
State a b c X Y Z B
δ(q4, Z) = (q5, Z , R)
q0 (q1, X, R) (q4, Y , R) δ(q5, Z) = (q5, Z , R)
δ(q5, B) = (q6, B , R/L) Halt
q1 (q1, a, R) (q2, Y, R)
q4 (q4, Y , R) (q5, Z , R)
q6 Halt
Transition Functions:
δ(q0, a) = (q1, X, R)
δ(q1, a) = (q2, X, R)
δ(q2, a) = (q2, a, R)
δ(q2, Y) = (q2, Y, R)
δ(q2, b) = (q3, Y, L)
δ(q3, a) = (q3, a , L)
δ(q3, Y) = (q3, Y , L)
δ(q3, X) = (q0, X , R)
δ(q0, Y) = (q4, Y , R)
δ(q4, Y) = (q4, Y , R)
δ(q4, B) = (q5, B , R/L) Halt
Transition Functions:
δ(q0, a) = (q1, B, R)
δ(q1, a) = (q1, a, R)
δ(q1, b) = (q1, b, R)
δ(q1, B) = (q2, B, L)
δ(q2, a) = (q3, B, L)
δ(q3, a) = (q3, a, L)
δ(q3, b) = (q3, b, L)
δ(q3, B) = (q0, B, R)
δ(q0, b) = (q4, B, R)
δ(q4, a) = (q4, a, R)
δ(q4, b) = (q4, b, R)
δ(q4, B) = (q5, B, L)
δ(q5, b) = (q6, B, L)
δ(q6, a) = (q6, a, L)
δ(q6, b) = (q6, b, L)
δ(q6, B) = (q0, B, R)
δ(q0, B) = (q7, B , R/L) Halt
Recursively Enumerable languages
• Recursively Enumerable languages: If any Turing Machine can be designed to accept all
string of the given language, then the language is called recursively enumerable
language.
• Recursively enumerable languages are the formal languages that can be decide-able,
( fully or partially). According to the Chomsky hierarchy of formal languages, we can
see the recursively enumerable languages as type 0 languages. some examples of
recursively enumerable languages are;
• Recursive languages
• Regular languages
• Context-sensitive languages
• Context-free languages and many more.
• Recursively enumerable language is recursively enumerable if it can be accepted by the
Turing machine (Read More). This is the main reason why recursively enumerable
languages are also called Turing recognizable languages. Please note that the Turing
machine is a very strong machine as compared to the finite state automata or
pushdown automata and is more powerful than many other machines.
Properties of Recursively enumerable languages
• Union ,Intersection, Complement
Union of RE languages
• Let’s revise union of sets;
• Set 1={a, b, c}
• Set 2={b, c, d}
• Set 1 Union Set 2 = {a, b, c, d}
• Now let’s understand the same concept in Turing Machine;
• Suppose a system has 2 Turing Machines, TM1, and TM2.
• If TM1 halts then all the system halts.
• If TM1 crash then system checks that TM2 is ready to halt or not? If TM2 halts then system
halts because this is union and the union means that
– If TM1 halts then system halts
– If TM1 does not halt, and TM2 halts then system halts
– If TM1 and TM2 or TMn halts then system halts
• Figure: Union of RE languages
• The intersection of RE languages
• Let’s revise the intersection of sets;
• Set 1={a, b, c}
• Set 2={b, c, d}
• Set 1 Intersection Set 2 = {b, c}
• Now let’s understand the same concept in Turing Machine;
• Suppose a system has 2 Turing Machines, TM1, and TM2.
• If TM1 crash then all the system crash.
• If TM1 halts then system checks that TM2 is ready to halt or not? After this, If TM2 halts then
system halts because this is intersection and the intersection means that
– If TM1 crash then system crash
– If TM1 halts then check TM2 or TMn, and if TM2 is also halted, the system halts.
– If TM1 and TM2 or TMn crash then the system crash