Unit 4 CFG

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 137

Context Free Grammar

Syllabus
Unit Contents Lectures
1. Basic Mathematical Objects and Mathematical Induction: Sets, Logic, Functions, Relations, Alphabets, Strings, 5
Language, Principle of Mathematics Induction, Recursive Definition
2. Regular Expression and finite Automata: Regular Language and Regular Expression, Memory required to recognize a 10
language, Finite Automata, Capability and Limitations of finite State Machine, Deterministic Finite Automata, Non
Deterministic Finite Automata, NFA with ϵ moves, Regular Sets and Regular Expressions, Equivalence of DFA and NDFA,
NFA from Regular Expressions, Regular Expressions from DFA, Moore versus Mealy machines, Two way finite automata
with one way, Kleen’s Theorem, Applications of Finite Automata.
3. Regular and No in Regular Languages: Criterion for Regularity, Minimal Finite Automata, Pumping Lemma for Regular 5
Languages, Decision Problems, Regular language and Computers.
4. Context Free Grammars: Introduction, Definition, Regular Grammar, Derivation Trees, Ambiguity, Simplified Forms and 5
Normal Forms, Applications.
5. Pushdown Automata: Definition, Moves, Instantaneous Descriptions, Language Recognized by PDA, Deterministic PDA, 10
Acceptance by Final State and Empty Stack, Equivalence of PDA, Pumping Lemma for CFL, Interaction and
Complements of CFL, Decision Algorithms.
6. Turing Machines: Definitions and Examples, Computing Partial Functions with Turing Machines (TM), Combining Turing 5
Machines, Variations of Turning Machines, Multi Tape Turing Machines, Non Deterministic Turing Machine, Universal
Turing Machine, Church Thesis.
7. Recursively Enumerable Languages: Recursively Enumerable and Recursive enumerating Language, Context Sensitive 5
and Chomsky Hierarchy, Non Recursive Language and Unsolvable Problems, Halting Problem, Rice Theorem, Post
Correspondence Problem, Computational Complexity: Discussion on P, NP, NPC and NP Hard Problems.
Lecture Delivered by Surya Narayan Prasad 2
Introduction
● Let a language L1 = { akbk|k>=0} over {a,b}. “aabb”
● The grammar rules for the language L1 can be defined as
follows:-
● Rule 1: ϵ belongs to L1. (‘ϵ’ zero times symbol ‘a’ and zero
times symbol ‘b’).
● Rule 2: for every string ‘w’ belongs to L1, “awb” belongs to
L1.
● Rule 3: Nothing else belongs to L1. “ab→awb →aabb →
aaabbb”

Lecture Delivered by Surya Narayan Prasad 3


Introduction
● Leta language L1 = {ϵ,ab,aabb,aaabbb,aaaabbbb, …} over
{a,b}.

Lecture Delivered by Surya Narayan Prasad 4


Introduction …
● Since k can be 0, ‘ϵ’ is a valid string in the language L1.
● The definition in the form of “awb”, in rule 2 embeds equal
number of a’s and b’s in every valid string in Language L1.
● Rule 3 prohibits any other mechanism to generate a string
for the language L1.

Lecture Delivered by Surya Narayan Prasad 5


Introduction …
● The informal production system for the language L1 can be
“S→ϵ|aSb is saying that either the string S→ϵ is produced
or the string S→aSb is produced ”, where S is the variable
that describes the initial form of strings belonging to a
language. P = {S→ϵ, S→aSb}, ϵ,ab, aabb, aaabbb, aaaabbbb
● Let the string a3b3 belongs to L1 to be generated.
● The required production system is “S →aSb →aaSbb →
→aaaSbbb → aaaϵbbb → aaabbb”.

Lecture Delivered by Surya Narayan Prasad 6


Introduction …
● Context Free Grammar i.e. CFG is defined as 4 tuples (VN, Σ,
P, S), where P is a set of production rules of the form (One)
Non Terminal = Finite Set of Terminals and /or non
terminals.

Lecture Delivered by Surya Narayan Prasad 7


Introduction …
● The general form of production in CFG states that the non
terminal in the left hand side of production is free from
context that is there is neither left nor right context.
● It means, G is a context free grammar, if and only if every
production it has of the form A → α, where A belongs to VN,
α belongs to (VN U Σ)*.

Lecture Delivered by Surya Narayan Prasad 8


Introduction …
●A context free grammar for generating equal size of a and b
in the form anbn will be given as S → aAb, A → aAb|ϵ, then
“G = ({S,A}, {a,b}, {S → aAb, A → aAb|ϵ}, S)”.
● Here VN = {S,A} is the set of non terminals, ∑ = {a,b} is the
set of terminals i.e. alphabets, P = {S → aAb, A → aAb|ϵ} is
the set of production rules and S is the starting symbol.

Lecture Delivered by Surya Narayan Prasad 9


Introduction …
● L={ anbn ,n>=0}
●G = (VN={S,A},∑= {a,b}, P = {S → ϵ, S→aAb, A → aAb, A → ϵ},
S)
● P = {S → ϵ, S→aAb, A → aAb, A → ϵ} is the set of production
rules, S is the starting symbol, S and A are non terminals.
● G = (VN={S,A},∑= {a,b}, P = {S → ϵ|aAb, A→aAb|ϵ}, S)

Lecture Delivered by Surya Narayan Prasad 10


Introduction …
● L={ϵ,ab,aabb, aaabbb}
● Production Rule for ϵ String belonging to the language L
● S→ϵ
● Production Rule for “ab” String belonging to the language L
● S→aAb,A → ϵ
● Production Rule for “aabb” String belonging to the language
L
● S→ϵ, S→aAb, A→ aAb, A→ ϵ

Lecture Delivered by Surya Narayan Prasad 11


Introduction …
● Generation of String “ab” belonging to the language L
● P= {S→aAb,A→ϵ}
● S→aAb→ aϵb→ab
● Generation of String “aabb” belonging to the language L
● P= {S→ϵ, S→aAb, A→aAb, A→ϵ}
● S→aAb→aaAbb→ aaϵbb→aabb
● Generation of String “aaabbb” belonging to the language L
● P= {S→ϵ, S→aAb, A→aAb, A→ϵ}
● S→aAb→aaAbb→ aaaAbbb→aaaϵbbb →aaabbb

Lecture Delivered by Surya Narayan Prasad 12


Introduction …
● If we want to generate aaabbb i.e. a*b* then
● S → aAb (because S is the starting symbol)
● S →aaAbb (replacing A with aAb)
● S →aaaAbbb (replacing A with aAb)
●S →aaaϵbbb (replacing A with ϵ)
● S →aaabbb

Lecture Delivered by Surya Narayan Prasad 13


How to Check Whether a String Belongs to a
Grammar or Not?
● Startwith the starting symbol and choose the longest
production that matches to the given string.
● Replace the variables with its most appropriate production
and repeat the process until string is generated or no other
production is left.

Lecture Delivered by Surya Narayan Prasad 14


How to Check Whether a String Belongs to a
Grammar or Not? …
● Let G is a grammar such that G= ({S,A,B}, {0,1},{S → 0B|1A, A → 0
| 0S |1AA | ϵ , B → 1|1S | 0BB},S), then there is the production
rule “S → 0B|1A, A → 0 | 0S |1AA | ϵ , B → 1|1S | 0BB”, we try
to verify that whether the grammar generates the string
“00110101”.
● Solution: -
● S → 0B | 1A
● As the first element of the given string is 0, we will choose S
→ 0B.
● S → 0B (As B is there in our string, we are going to choose the
production rule B → 1|1S | 0BB)

Lecture Delivered by Surya Narayan Prasad 15


How to Check Whether a String Belongs to a
Grammar or Not? …
● As the second element of the given string is 0, we will
choose B → 0BB.
● S → 0B → 00BB (Replaced B with 0BB)
● As the third element of the given string is 1, we will
choose B → 1.
● S → 0B → 00BB → 001B (Replaced B with 1)
● As the fourth element of the given string is 1 and the
string is not terminating there, we will choose B → 1S.

Lecture Delivered by Surya Narayan Prasad 16


How to Check Whether a String Belongs to a
Grammar or Not? …
●S → 0B → B → 00BB → 001B → 0011S (Replaced B with
1S)
● As the fifth element of the given string is 0 and the non
terminal S is there, we will choose S → 0B.
● S → 0B → B → 00BB → 001B → 0011S → 00110B
(Replaced S with 0B)
● As the sixth element of the given string is 1 and the string
is not terminating there, we will choose B → 1S.
● S → 0B → B → 00BB → 001B → 0011S → 00110B →
001101S(Replaced B with 1S)
Lecture Delivered by Surya Narayan Prasad 17
How to Check Whether a String Belongs to a
Grammar or Not? …
● As the seventh element of the given string is 0 and the
string is not terminating, we will choose S → 0B.
● S → 0B → B → 00BB → 001B → 0011S → 00110B →
001101S → 0011010B (Replaced S with 0B)
● As the eighth element of the given string is 1 and the
string is terminating, we will choose B →1.
● S → 0B → B → 00BB → 001B → 0011S → 00110B →
001101S → 0011010B → 00110101 (Replaced B with 1)
and hence we find that the given string is generated by
the given grammar.
Lecture Delivered by Surya Narayan Prasad 18
How to Check Whether a String Belongs to a
Grammar or Not?
● Thus, we followed the production path S → 0B
● S → 00BB
● S → 001B
● S → 0011S
● S → 00110B
● S → 001101S
● S → 0011010B
● S → 00110101
● Hence the given string 00110101 is accepted by the given
grammar.
Lecture Delivered by Surya Narayan Prasad 19
Parse Tree: An Introduction
● Derivation Tree is termed as Parse Tree.
● The strings generated by a context free grammar G(V, Σ, P, S)
can be represented by a hierarchical structure termed as
tree or derivation tree or parse tree.
● A derivation tree or parse tree for a context free grammar
G(V,Σ, P,S) is a that satisfies the following conditions : -

Lecture Delivered by Surya Narayan Prasad 20


Parse Tree: An Introduction
● Every vertex has a “label” or “terminal” or ‘ϵ’ or “variable”
● The root has label ‘S’
● The label of internal vertex is “variable”.
● If vertices a1, a2, a3, … have labels α1, α2 , α3, … are sons
of vertex a with label A then A → α1, α2 , α3, … is
production in P.
● The vertex ‘n’ is a leaf if and only if its label is “a ∈ Σ or ϵ”.
The vertex ‘n’ is the only son of its father if and only if its
label is ‘ϵ’.

Lecture Delivered by Surya Narayan Prasad 21


Parse Tree: An Introduction …
● Let
CFG G(VN = {S, A}, ∑ = {a, b},P = {S →AA, A → AAA |
bA | Ab | a} ,S)
● Thenthe derivation tree or parse tree for the string
“bbaaaab” given below : -

Lecture Delivered by Surya Narayan Prasad 22


Parse Tree: An Introduction …
S

A A

b A A A A

b A a a A b

a a

Lecture Delivered by Surya Narayan Prasad 23


Yield of Derivation Tree(or Parse Tree)
● The concatenation of the labels of leaf nodes in the left to
right ordering without repetition, results in the yield of
derivation or parse tree.

Lecture Delivered by Surya Narayan Prasad 24


Sub Tree of Derivation Tree(or Parse Tree)
● The sub tree of a parse tree is a tree having following
characteristics: -
● The root of sub tree is some vertex ‘v’ of derivation or
parse tree where v belongs to V.
● The vertex of sub tree are descendants of ‘v’ with their
labels.
● The edges of sub tree connect the descendants of ‘v’.

Lecture Delivered by Surya Narayan Prasad 25


Sub Tree of Derivation Tree(or Parse Tree) …
● Considering the Parse Tree for The String “bbaaaab”, The
Sub Tree is
A A A A

b A A b b A a

b A a a

Lecture Delivered by Surya Narayan Prasad 26


Types of Derivation Tree(or Parse Tree) …
● Left Most Derivation Tree
● A tree is said to be left most derivation tree if and only if
the ordering of the decomposed variables is from left to
right.
● Right Most Derivation Tree
● A tree is said to be right most derivation tree if and only if
the ordering of the decomposed variables is from right to
left.

Lecture Delivered by Surya Narayan Prasad 27


Types of Derivation Tree(or Parse Tree) …
● Generate the string “aabaa” from the grammar “G(V = {S,A},
∑ ={a,b}, P = {S →aAS |aSS |ϵ, A →SbA |ba},S)”.
● Left Most Derivation Tree
● S →aSS (This is due to ‘a’ being the first element of string.)
● S →aaASS (replacing left S with aAS)
● S →aabaSS (replacing left A with ba)
● S →aabaaSSS (replacing left S with aSS)
● S →aabaaϵSS (replacing left S with ϵ )

Lecture Delivered by Surya Narayan Prasad 28


Types of Derivation Tree(or Parse Tree) …
●S →aabaaϵϵS (replacing left S with ϵ )
● S →aabaaϵϵϵ (replacing left S with ϵ )
● S →aabaa

Lecture Delivered by Surya Narayan Prasad 29


Types of Derivation Tree(or Parse Tree) …
● Right MostDerivation Tree
● S →aSS (This is due to ‘a’ being th first element of string.)
● S →aSaAS (replacing right S with aAS)
● S →aSaAaSS (replacing right S with aSS)
● S →aSaAaSϵ (replacing right S with ϵ)
● S →aSaAaϵϵ (replacing right S with ϵ )
● S →aSabaa (replacing right A with b )
● S →aϵabaa (replacing right S with ϵ )
● S →aabaa
Lecture Delivered by Surya Narayan Prasad 30
Simplification of CFG
● The simplification of CFG requires to eliminate the
production, variable and terminals having following
characteristics : -
● The production in which a “variable” does not derive a
terminal string.
● The symbol (V U Σ) not appearing in any sentential form.
● Unit Production (A → B)
● Null Production (A → ε)
● Let our Grammar be “G(V = {S,A}, ∑ ={a,b}, P = {S →aAS
|aSS |ϵ, A →SbA |ba},S)”
Lecture Delivered by Surya Narayan Prasad 31
Simplification of CFG …
● Removal of Null Production
● A → ϵ is a null production. A is a nullable variable.
● ‘ϵ’ should have to be removed because it creates
difficulties for the compilers.
● There are two steps for the same
● Scan the nullable variable and identify them.
● Find P = P (i.e. null production)

Lecture Delivered by Surya Narayan Prasad 32


Simplification of CFG …
● Example: - “Removal of Null Production”
● Find a CFG without null productions equivalent to the
grammar defined by
● S →ABaC
● A →BC
● B →b|ϵ
● C →D|ϵ
●D → d
● G({S,A,B,C,D}, {a,b,d}, {S →ABaC, A →BC, B →b|ϵ, C
→D|ϵ, D → d}, Lecture
S) Delivered by Surya Narayan Prasad 33
Simplification of CFG …
● Step 1
● Scan the nullable variable and identify them.
● First ofall let, nullable variable N is empty i.e. N = { }
● Now we are finding that variables B(B →ϵ) and C(C
→ϵ) produce Null, then N = {B, C}.
● We are finding that variable A(A→BC) is directly
related with variables B and C. Then N = { A, B, C }
● Variable S cannot be nullable and hence cannot be
added to N.
Lecture Delivered by Surya Narayan Prasad 34
Simplification of CFG …
● Step 2
●P = P (null productions)
● S → ABaC means S → BaC | AaC | ABa | aC | Ba | Aa
|a
● A → BC means A → C | B
●B → b
●C → D
●D → d

Lecture Delivered by Surya Narayan Prasad 35


Simplification of CFG …
● Thus thefinal grammar will be
● S → ABaC | BaC | AaC | ABa | aC | Ba | Aa | a
● A → C | B | BC
●B → b
●C → D
●D → d

Lecture Delivered by Surya Narayan Prasad 36


Simplification of CFG …
● Removal of Unit Production
● Any production of a context free grammar of the form A
→ B, where A, B ϵ V is termed as unit production.
● There are two steps for the same.
● Find P = P (Unit Productions)
● Drawing a dependency graph with an edge (C,D),
whenever the grammar has a unit production C → D.

Lecture Delivered by Surya Narayan Prasad 37


Simplification of CFG …
● Removal of Unit Production
● Find the CFG without unit production equivalent to the
grammar given by
● S → Aa | B
● B → A | bb
● A → a | bc | B

Lecture Delivered by Surya Narayan Prasad 38


Simplification of CFG …
● Removal of Unit Production
● Find the CFG without unit production equivalent to the
grammar given by
● S → Aa | B
● B → A | bb
● A → a | bc | B

Lecture Delivered by Surya Narayan Prasad 39


Simplification of CFG …
● Step1
● P = P - (unit productions)
● S → Aa | B
● B → bb
● A → a | bc

Lecture Delivered by Surya Narayan Prasad 40


Simplification of CFG …
● Removal of Unit Production
● Step 2

S A B

Lecture Delivered by Surya Narayan Prasad 41


Simplification of CFG …
● Removal of Unit Production
● The new rules
● S → aa | bc | bb
● B → bb
● A → a | bc

Lecture Delivered by Surya Narayan Prasad 42


Simplification of CFG …
● Removal of Unit Production
● The equivalent grammar is
● S → a | bc | bb | Aa
● A → bb | a |bc
● B → a | bc | bb

Lecture Delivered by Surya Narayan Prasad 43


Simplification of CFG …
● Removal of Useless Productions
● Let G = (V, Σ, S, P) be a context free grammar.
● A variable A ϵ V is said to be useful iff there is at least one
ω ϵ L(G) such that S →* xAy →* ω with x,y ϵ (V U Σ)*.
● In other words, a variable is useful iff it occurs in at least
one derivation.
● A variable if not useful is termed as useless.

Lecture Delivered by Surya Narayan Prasad 44


Simplification of CFG …
● Removal of Useless Productions
● A production is termed as useless iff it involves any
useless variable(s).
● A variable may be useless because there is no way of
getting a terminal string from it.
● Considering the following grammar
● S → A → aA| ϵ → a(aA|ϵ )|ϵ
● A → aA |ϵ
● B → bA
Lecture Delivered by Surya Narayan Prasad 45
Simplification of CFG …
● In the above grammar, the variable B is useless and so is
the production B → bA

Lecture Delivered by Surya Narayan Prasad 46


Simplification of CFG …
● Removal of Useless Productions
● In the above grammar, the variable B is useless and so is
the production B → bA.
● Although B can derive a terminal string but there is no
way we can achieve S →* xBy.

Lecture Delivered by Surya Narayan Prasad 47


Simplification of CFG …
● Removal of Useless Productions
● Eliminate useless symbols and productions from G(V, Σ, S,
P) where V = {S, A, B, C}, Σ = {a, b} and P consists of
● S → aS | A | C
● A→a
● B → aa
● C → aCb

Lecture Delivered by Surya Narayan Prasad 48


Simplification of CFG …
● Removal of Useless Productions
● First we have to identify the set of variables that can lead
to a terminal string. This is because A →a and B →bb,
then the variables A and B falls in this set. So does S,
because S →A →a. This argument cannot be made with C.
thus C is identified as a useless variable.
● Removing C and its corresponding productions from
grammar G, we led to the

Lecture Delivered by Surya Narayan Prasad 49


Simplification of CFG …
● Removal of Useless Productions
● Removing C and its corresponding productions from
grammar G, we led to the grammar G1 with variables V1=
{S,A,B} and terminals Σ = {a} and production P consists of
● S →aS | A
● A →a
● B →aa

Lecture Delivered by Surya Narayan Prasad 50


Simplification of CFG …
● Removal of Useless Productions
● Now, we want to eliminate the variables that cannot be
reached from the start variable. For this we have to draw
a dependency graph for the variables. As we know that a
variable is useful iff there is a path from the vertex
labelled as ‘S’ to the vertex labelled with that variable

Lecture Delivered by Surya Narayan Prasad 51


Simplification of CFG …
● Removal of Useless Productions

S A B

Lecture Delivered by Surya Narayan Prasad 52


Simplification of CFG …
● Removal of Useless Productions
● The above dependency graph clearly signals that there is
no path from vertex labelled ‘S’ to the vertex labelled with
‘B’.
● Thus variable b is useless and hence the final grammar is
given by
● S → aS | A
● A→a

Lecture Delivered by Surya Narayan Prasad 53


Pushdown Automata
●A Pushdown Automata is a Tool or Machine to Implement
Context Free Language(s).
● The Biggest Drawback of Finite Automata is the Absence of
Memory i.e. there is no mechanism to remember the count
of input symbols or to match the relationship between the
different types of symbols occurring in the given string.
● Due to this reason the language L = {0n1n | n >=1} is not
regular.

Lecture Delivered by Surya Narayan Prasad 54


Pushdown Automata …
● The implementation of language L on a machine requires the
machine to remember the number of 0s in the input string
and then to match this number with the number of 1s.
● As we know that the language L = {0n1n | n>=1} is a Context
Free Language.
● PDA, the tool for implementation of the CFL must be coupled
with some kind of memory attachment.

Lecture Delivered by Surya Narayan Prasad 55


Pushdown Automata …
● PDA, the tool for implementation of the CFG must be
coupled with some kind of memory attachment.
● The Memory Attachment in the PDA is in the form of Stack.
● To implement the above language L on PDA, we can keep
pushing a sequence of 0s into the stack one by one till all 0s
are pushed.

Lecture Delivered by Surya Narayan Prasad 56


Pushdown Automata …
● Now 1s in the input string can be used to pop 0s from the
stack with each 1 popping one 0. If number of 0s and 1s are
equal, then at the end of the string, the stack of PDA will be
empty.
● An empty stack at the consumption of the string indicates
the acceptance of the string by the PDA.

Lecture Delivered by Surya Narayan Prasad 57


Pushdown Automata …
● Considering the CFL L = {a2nbn | n>0}
● In this situation, we can go on pushing the input sequence of
a’s into the stack one by one till all the a’s are pushed.
● Now b’s can be used to pop a’s from the stack, with each b
popping two a’s ; if the number of a’s is exactly double that
of b’s, then at the end of the string, the stack of the PDA will
be empty.

Lecture Delivered by Surya Narayan Prasad 58


Pushdown Automata …
● An empty stack at the consumption of the string indicates
the acceptance of the string by the PDA.

Lecture Delivered by Surya Narayan Prasad 59


Basic Structure of Pushdown Automata
● An input tape on which the input string is placed.
● A read head which reads the character in the input string
one by one. This is also associated with a designated set of
states, in one of which it can exist at a given instant of time.
The head has a predefined starting state, which is defined in
the description of the PDA.
● A stack (pushdown store) in the form of auxiliary memory.

Lecture Delivered by Surya Narayan Prasad 60


Basic Structure of Pushdown Automata …
Input Tape

Read Head

Pushdown Store

Lecture Delivered by Surya Narayan Prasad 61
Pushdown Automata
●APushdown Automata can be defined as a set of 7
tuples (Q, Σ, τ, δ, q0, Z, F), where
●Q is the finite non empty set of states
● Σ is finite non empty set of input symbols
● τ (Tou) is a finite non empty set of stack alphabets
● q0 is the initial state
● Z | Z0 is the initial Stack symbol. It is resident in the stack
from its beginning.
Lecture Delivered by Surya Narayan Prasad 62
Pushdown Automata
●F is the set of final states. A PDA can accept the strings in
two ways, either by a final state or null store. In case of
acceptance by a final state, a string is accepted by the PDA
if, at the end of the string, the read head is in one of the
final states. F is sub set of Q. In acceptance of null store, a
string is accepted by the PDA if, at then end of the string,
the pushdown store is empty. In this case F = φ.
● δ is the transition function which maps Q X (Σ U {ϵ} } X τ
to Q X τ*

Lecture Delivered by Surya Narayan Prasad 63


Types of Pushdown Automata
● Deterministic
Pushdown Automata
● Non – Deterministic Pushdown Automata

Lecture Delivered by Surya Narayan Prasad 64


Working of Pushdown Automata
● To illustrate the working of the PDA, first we design a PDA M
to accept the language L1 = {0n1n |n>=1}.
● This PDA will accept the strings of the type 01, 0011, 000111,
00001111 etc. which begins with a substring of 0s followed
by the substring of 1s such that the number of 1s and that of
0s are equal.

Lecture Delivered by Surya Narayan Prasad 65


Working of Pushdown Automata …
● Let w = 00001111 be the string to be checked for the
belongingness to the language L1. It is loaded on the input
tape of PDA M.
● The read head is in its initial state q0 and points to the first
character of the string w.
● The pushdown store of M contains the initial stack symbol
Z0.

Lecture Delivered by Surya Narayan Prasad 66


Working of Pushdown Automata …
● The initial state of the PDA M is given as follows
ϵ ϵ 0 0 0 0 1 1 1 1 ϵ ϵ

Read Head

Pushdown Store

Z0
Lecture Delivered by Surya Narayan Prasad 67
Working of Pushdown Automata …
● The instantaneous state of a PDA is defined by three
parameters. They are current state of the read head, part of
the string yet to be processed and the current contents of
the pushdown store.
● Thus the initial state of the PDA M is δ(q0,00001111, Z0).
● The PDA works as follows

Lecture Delivered by Surya Narayan Prasad 68


Working of Pushdown Automata …
● The read head reads the first symbol ‘0’ of the given string
“00001111” from the input tape and pushes it into the stack
and the state of read head changed from q0 to q1.
● This change of state from q0 to q1 is done to ensure that
there is at least one 0 in the string, keeping in view the
requirement n>=1. After this transition, the state of the PDA
m changes to (q1, 0001111, 0Z0).

Lecture Delivered by Surya Narayan Prasad 69


Working of Pushdown Automata …
● The PDA reads next 0 from the input tape and pushes it into
the stack as well. The state of the read head remains as q1.
after the transition, the state of the PDA M changes to (q1,
001111, 00Z0).
● The process continues till all the 0s in the string are pushed
into the stack. These transitions lead the PDA M to the state
(q1, 1111, 0000Z0).

Lecture Delivered by Surya Narayan Prasad 70


Working of Pushdown Automata …
● Now the read head reads the next symbol 1 from the input
tape and pops a 0 from the stack. The read head changes its
state from q1 to q2. This transition brings the PDA M to the
state (q2, 111, 000 Z0).
● The read head keeps reading 1s from the input tape one by
one and popping 0s one by one till all the 0s are removed
from the stack. The current state of the PDA M is (q2, ϵ, Z0).
The null string indicates that the whole of the input string
has been consumed.
Lecture Delivered by Surya Narayan Prasad 71
Working of Pushdown Automata …
● The contents of the pushdown store Z0, indicates that all the
0s have been successfully popped by an equal number of 1s.
The only requirement now is to make the pushdown store
empty.
● Thus we include a transition in the transition set δ to
accomplish this. The transition is (q2, ϵ, Z0) → (qF, ϵ, Z0) i.e.
(q2, ϵ, Z0) Ⱶ (q3, ϵ, ϵ), where ‘Ⱶ’ is termed as “half H”.

Lecture Delivered by Surya Narayan Prasad 72


Working of Pushdown Automata …
● The initial state of the PDA M is given as follows
ϵ ϵ 0 0 0 0 1 1 1 1 ϵ ϵ

Transition is δ(q0,00001111,Z0)→(q1,0001111,0Z0)

Pushdown Store
Transition Function used is δ(q0,0,Z0) Ⱶ(q1, 0Z0)


0
Z0
Lecture Delivered by Surya Narayan Prasad 73
Working of Pushdown Automata …
● The initial state of the PDA M is given as follows
ϵ ϵ 0 0 0 0 1 1 1 1 ϵ ϵ

δ(q1,0001111, 0Z0)→(q1,001111,00Z0)

Pushdown Store

0
0
Z0
Lecture Delivered by Surya Narayan Prasad 74
Working of Pushdown Automata …
● The initial state of the PDA M is given as follows
ϵ ϵ 0 0 0 0 1 1 1 1 ϵ ϵ

δ(q1,001111, 00Z0)→(q1,01111,000Z0)

Pushdown Store
0


0
0
Z0
Lecture Delivered by Surya Narayan Prasad 75
Working of Pushdown Automata …
● The initial state of the PDA M is given as follows
ϵ ϵ 0 0 0 0 1 1 1 1 ϵ ϵ

δ(q1,01111,000Z0)→(q1,1111, 0000Z0)

Pushdown Store
0
0


0
0
Z0
Lecture Delivered by Surya Narayan Prasad 76
Working of Pushdown Automata …
● The initial state of the PDA M is given as follows
ϵ ϵ 0 0 0 0 1 1 1 1 ϵ ϵ

δ(q1, 1111,000Z0)→(q2,111, 000Z0)

Pushdown Store
0


0
0
Z0
Lecture Delivered by Surya Narayan Prasad 77
Working of Pushdown Automata …
● The initial state of the PDA M is given as follows
ϵ ϵ 0 0 0 0 1 1 1 1 ϵ ϵ

δ(q2, 111,000Z0)→(q2,11, 00Z0)

Pushdown Store

0
0
Z0
Lecture Delivered by Surya Narayan Prasad 78
Working of Pushdown Automata …
● The initial state of the PDA M is given as follows
ϵ ϵ 0 0 0 0 1 1 1 1 ϵ ϵ

δ(q2, 11,00Z0)→(q2,1, 0Z0)

Pushdown Store

0
Z0
Lecture Delivered by Surya Narayan Prasad 79
Working of Pushdown Automata …
● The initial state of the PDA M is given as follows
ϵ ϵ 0 0 0 0 1 1 1 1 ϵ ϵ

δ(q2, 1,0Z0)→(q2,ϵ, Z0)

Pushdown Store

Z0
Lecture Delivered by Surya Narayan Prasad 80
Working of Pushdown Automata …
● The initial state of the PDA M is given as follows
ϵ ϵ 0 0 0 0 1 1 1 1 ϵ ϵ

δ(q2, ϵ, Z0)→(qf,ϵ, ϵ) Null Transition

Pushdown Store

ϵ
Lecture Delivered by Surya Narayan Prasad 81
Working of Pushdown Automata …
● Itis surprising that the above transition has occurred without
consumption of an input symbol. A PDA allows for null string
transition.
● The empty pushdown store indicates the acceptance of the
string 00001111 by the PDA M.

Lecture Delivered by Surya Narayan Prasad 82


Working of Pushdown Automata …
● The total transitions occurring in the PDA M for the
acceptance of the string 00001111 are δ(q0, 00001111, Z0) →
δ(q1, 0001111, 0Z0) → δ(q1, 001111, 00Z0) → δ(q1, 01111,
000Z0) → δ(q1, 1111, 0000Z0) → δ(q2, 111, 000Z0) → δ(q2,
11, 00Z0) → δ(q2, 1, 0Z0) → δ(q2, ϵ, Z0) → δ(q3, ϵ, Z0 |ϵ).
● The function starts from the initial state δ(q0, 00001111, Z0)
and transitively leads to the acceptor position δ(q3, ϵ, ϵ).
● This transitive process can be written as δ(q0, 00001111, Z0)
→ * δ(q3, ϵ, ϵ) by omitting the intermediate states.
Lecture Delivered by Surya Narayan Prasad 83
Working of Pushdown Automata …
● The following transition table illustrates the reading process
of the string “00001111”. Transition Transition Function used
δ(q0, 00001111,Z0) → δ(q1, 0001111,0Z0) δ(q0, 0, Z0) Ⱶ(q1, 0Z0)
δ(q1, 0001111,0Z0) → δ(q1, 001111,00Z0) δ(q1, 0, 0) Ⱶ(q1, 00)
δ(q1, 001111,00Z0) → δ(q1, 01111,000Z0) δ(q1, 0, 0) Ⱶ(q1, 000)
δ(q1, 01111,000Z0) → δ(q1, 1111,0000Z0) δ(q1, 0, 0) Ⱶ(q2, 0000)
δ(q1, 1111,0000Z0) → δ(q2, 111,000Z0) δ(q2, 1, 0) Ⱶ(q2, 000)
δ(q2, 111,000Z0) → δ(q2, 11,00Z0) δ(q2, 1, 0) Ⱶ(q2, 00)
δ(q2, 11,00Z0) → δ(q2, 1,0Z0) δ(q2, 1, 0) Ⱶ(q2, 0)
δ(q2, 1,0Z0) → δ(q2, ϵ,Z0) δ(q2, 1, 0) Ⱶ(q2, Z0)
δ(q2, ϵ,Z0) → δ(q3, ϵ,Z0) δ(q2, ϵ, Z0) Ⱶ(q3, Z0)

Lecture Delivered by Surya Narayan Prasad 84


Working of Pushdown Automata …
● Thefollowing transition graph illustrates the reading of
00001111.
1, 00*Z0/0*Z0
0, 0*Z0/00*Z0

1,0/000Z0
0,Z0/0Z0 ϵ,Z0/Z0
q0 q1 q2 q3

Lecture Delivered by Surya Narayan Prasad 85


Working of Pushdown Automata …
● The transition table for the acceptance of the string
“00001111”.
● Considering the situation when number of 0s and 1s are not
equal.
● Let number of 0s is more than that of 1s say 00000111.
● The PDA M starts from the initial state δ(q0, 00000111,Z0)
and transitively we have, δ(q0, 00000111,Z0) → * δ(q1,
111,00000Z0) → * δ(q0, ε,00Z0)

Lecture Delivered by Surya Narayan Prasad 86


Working of Pushdown Automata …
● The PDA M starts from the initial state δ(q0, 00000111,Z0)
and transitively we have, δ(q0, 00000111,Z0) → δ(q1,
0000111,0Z0) → δ(q1, 000111, 00Z0) → δ(q1, 00111, 000Z0)
→ δ(q1, 0111, 0000Z0) → δ(q1, 111, 00000Z0) → δ(q2, 11,
0000Z0) → δ(q2, 1, 000Z0) → δ(q2 , ϵ , 00Z0) .
● Now we find that the stack is not empty.
● It means that the given string “00000111” is not accepted by
our PDA M.

Lecture Delivered by Surya Narayan Prasad 87


Working of Pushdown Automata …
● The transition table for the acceptance of the string
“00001111”.
● Considering the situation when number of 0s and 1s are not
equal. Let number of 0s is more than that of 1s say
00011111.
● The PDA M starts from the initial state δ(q0, 00011111,Z0)
and transitively we have, δ(q0, 00011111,Z0) → * δ(q1,
11111, 000Z0) → * δ(q2, 11,Z0)

Lecture Delivered by Surya Narayan Prasad 88


Working of Pushdown Automata …
● The PDA M starts from the initial state δ(q0, 00011111,Z0)
and transitively we have, δ(q0, 00011111,Z0) → δ(q1,
0011111,0Z0) → δ(q1, 011111, 00Z0) → δ(q1, 11111, 000Z0)
→ δ(q1, 1111, 00Z0) → δ(q1, 111, 0Z0) → δ(q2, 11, Z0) .
● Now we find that the stack is empty but the null symbol in
the input tape is not reached.
● It means that the given string “00011111” is not accepted by
our PDA M.

Lecture Delivered by Surya Narayan Prasad 89


Working of Pushdown Automata …
● Design a PDA M for the language L = {anb2n| n>=0}.
● Design a PDA M for the language L = {a2nbn| n>=0}.
● Design a PDA M for the language L = {anbm| n>=0}.

Lecture Delivered by Surya Narayan Prasad 90


Design a PDA M for the language L = {anb2n| n>=0}

● The possible strings are ϵ, abb,aabbbb, aaabbbbbb, …


● Case 1:
● When the input string is ‘ϵ’ , δ(q0, ϵ, Z0)→ (qf, ϵ, Z0 | ϵ).
● Case 2:
● When the input string is “abb”, δ(q0, abb, Z0) → (q1, bb,
aZ0 | ϵ) → (q1, bb, aZ0) → (q2, b, aZ0) → (q3, b, Z0)

Lecture Delivered by Surya Narayan Prasad 91


Working of Pushdown Automata …
● Since the stack is not empty at the complete consumption of
the string, the string 00000111 is not accepted by the PDA M
corresponding to the language L = {0n1n| n>0}
● Considering the situation when number of 0s and 1s are not
equal. Let number of 0s is less than that of 1s say 00011111.
● The PDA M starts from the initial state δ(q0, 00011111,Z0)
and transitively we have, δ(q0, 00011111,Z0) → * δ(q0,
111111,00000Z0) → * δ(q0, 11, Z0).

Lecture Delivered by Surya Narayan Prasad 92


Working of Pushdown Automata …
● The PDA M cannot make the transition from state (q2, 11, Z0)
onwards. The string is not accepted as it has not been
completely consumed by the PDA M.
● The complete instantaneous description of the PDA is as (qi,
w, α), where qi is the current state of read head, w is the
portion of the string still to be read and α is the string in the
stack.
● It is usually not in practice to write w and α completely but
instead the first symbol of w and topmost symbol of α.
Lecture Delivered by Surya Narayan Prasad 93
Working of Pushdown Automata …
● Thus a PDA with current state as (qi, 00011111, 0Z0) can be
written as (qi, 0, 0).
● The transition function δ for the PDA M. The first transition
function is δ(q0, 0, Z0) Ⱶ (q1, 0Z0), where Ⱶ is termed as half H.
● This transition function states that when the read head
encounters a 0 in the state q0, Z0 is on the top of the stack, it
pushes a 0 in the stack and moves to the state q1. The
symbol Ⱶ is the symbol for the transition.

Lecture Delivered by Surya Narayan Prasad 94


Working of Pushdown Automata …
● The RHS of the transition function contains only two
parameters q1 i.e. the new state and 0Z0, which indicates
that the 0 is pushed on Z0 in the stack.
● The two entries on the RHS of the transition function
indicate the consumption of the input symbol 0.
● The next transition function is δ(q1,0,0) Ⱶ(q1,00).

Lecture Delivered by Surya Narayan Prasad 95


Working of Pushdown Automata …
● Itindicates that when the read head in the state q1
encounters a 0 as the input symbol with 0 on the top of the
stack, the input symbol 0 is pushed into the stack. This
ensures the pushing of all subsequent 0s into the stack. The
read head stays in the state q1.

Lecture Delivered by Surya Narayan Prasad 96


Working of Pushdown Automata …
● Design a PDA M to accept the language L = {anb2n|n>=1}
● In the given problem, the number of b’s is double that of a’s.
● The string(s) in language L are abb, aabbbb, aaabbbbbb … .
● First all a’s are pushed into the stack and then two b’s are
used to pop one a.

Lecture Delivered by Surya Narayan Prasad 97


Working of Pushdown Automata …
● This can be done by associating the input symbol ‘b’ with a
on the top of the stack, with two different states say q2 and
q3, where q2 is used to pop ‘a’ and q3 is not used to pop a.
● The PDA M keeps on oscillating between these two states q2
and q3 till all a’s are popped from the stack.
● The transition functions are

Lecture Delivered by Surya Narayan Prasad 98


Working of Pushdown Automata …
● “aabbbb” is the input string.
● δ(q0, a, Z0) Ⱶ(q1, aZ0)
● δ(q1, a, a) Ⱶ(q1, aa)
● δ(q1, b, a) Ⱶ(q2, a)
● δ(q2, b, a) Ⱶ(q3, a)
● δ(q3, b, a) Ⱶ(q2, Z0)
● δ(q2, b, Z0) Ⱶ(q3, Z0)
● δ(q3, ϵ, Z0) Ⱶ(q4, Z0)

Lecture Delivered by Surya Narayan Prasad 99


Working of Pushdown Automata …
● The following transition graph illustrates the same

a, a*Z0/aa*Z0

a,Z0/aZ0 b, a/a b, a/ϵ ϵ, Z0 /ϵ


q0 q1 q2 q3 q4

b, a/a

Lecture Delivered by Surya Narayan Prasad 100


Working of Pushdown Automata …
● The following transition table illustrates the same
Transition Transition Function used
δ(q0, aabbbb,Z0) → δ(q1, abbbb,aZ0) δ(q0, a, Z0) Ⱶ(q1, aZ0)
δ(q1, abbbb,aZ0) → δ(q1, bbbb,aaZ0) δ(q1, a, a) Ⱶ(q1, aa)
δ(q1, bbbb,aaZ0) → δ(q2, bbb, aZ0) δ(q1, b, a) Ⱶ(q2, a)
δ(q2, bbb, aZ0) → δ(q3, bb, aZ0) δ(q2, b, a) Ⱶ(q3, a)
δ(q3, bb, aZ0) → δ(q2, b, Z0) δ(q3, b, a) Ⱶ(q2, Z0)
δ(q2, b, Z0) → δ(q3, ϵ, Z0) δ(q2, b, Z0) Ⱶ(q3, Z0)
δ(q3, ϵ, Z0) → δ(q4, ϵ, ϵ) δ(q3, ϵ, Z0) Ⱶ(q4, Z0)

Lecture Delivered by Surya Narayan Prasad 101


Working of Pushdown Automata …
● The following transition graph illustrates the same

a, a*Z0/aa*Z0

a,Z0/aZ0 b,a/a b,a/ε ε,Z0/ε


q0 q1 q2 q3 q4

b,a/a

Lecture Delivered by Surya Narayan Prasad 102


Working of Pushdown Automata …
● Design a PDA M to accept the language L = {a2nbn|n>=1}
● In the given problem, the number of a’s is double that of b’s.
● The string(s) in language L are aab, aaaabb, aaaaaabbb … .
● First all a’s are pushed into the stack and then one b is used
to pop two a’s.
● This can be done by popping the first ‘a’ from the top of the
stack on the input symbol ‘b’ and removing the second ‘a’
from the top of the stack using the null string ϵ.

Lecture Delivered by Surya Narayan Prasad 103


Working of Pushdown Automata …
● The PDA M keeps on oscillating between these two states q2
and q3 till all a’s are popped from the stack.
● The transition functions are

Lecture Delivered by Surya Narayan Prasad 104


Working of Pushdown Automata …
Transition Transition Function used
δ(q0, aaaabb,Z0) → δ(q1, aaabb,aZ0) δ(q0, a, Z0) Ⱶ(q1, aZ0)
δ(q1, aaabb,aZ0) → δ(q1, aabb,aaZ0) δ(q1, a, a) Ⱶ(q1, aaZ0)
δ(q1, aabb,aaZ0) → δ(q1, abb, aaaZ0) δ(q1, a, a) Ⱶ(q1, aaaZ0)
δ(q1, abb, aaaZ0) → δ(q1,bb, aaaaZ0) δ(q1, a, a) Ⱶ(q1, aaaaZ0)
δ(q1, bb, aaaaZ0Z0) → δ(q2, b, aaaZ0) δ(q1, b, a) Ⱶ(q2, aaaZ0)
δ(q2, ϵb, aaaZ0) → δ(q3, b, aaZ0) δ(q2, ϵ, a) Ⱶ(q3, aaZ0)
δ(q3, b, aaZ0) → δ(q2, ϵ, aZ0) δ(q3, b, a) Ⱶ(q2, aZ0)
Lecture Delivered by Surya Narayan Prasad 105
Working of Pushdown Automata …
Transition Transition Function used
δ(q2, ϵ, aZ0) → δ(q4, ϵ, Z0) δ(q2, ϵ, a) Ⱶ(q4, Z0)
δ(q4, ϵ, Z0) → δ(q4, ϵ, Z0) δ(q4, ϵ, Z0) Ⱶ(q4, Z0)

Lecture Delivered by Surya Narayan Prasad 106


Working of Pushdown Automata …
δ(q1, a, a) Ⱶ(q1, aaZ0)

δ(q2, ϵ, a) Ⱶ(q3, aaZ0)

δ(q0, a, Z0) Ⱶ(q1, aZ0) δ(q1, b, a) Ⱶ(q2, aaaZ0)


q0 q1 q2 q3
δ(q3, b, a) Ⱶ(q2, aZ0)

δ(q2, ϵ, a) Ⱶ(q4, Z0)

q4 δ(q4, ϵ, Z0) Ⱶ(q4, Z0)

Lecture Delivered by Surya Narayan Prasad 107


Working of Pushdown Automata …
● Let the input string be “aaaabb”.
● δ(q0, a, Z0) Ⱶ(q1, aZ0)
● δ(q1, a, a) Ⱶ(q1, aa)
● δ(q1, b, a) Ⱶ(q2, ε)
● δ(q2, ε, a) Ⱶ(q3, ε)
● δ(q3, b, a) Ⱶ(q2, ε)
● δ(q3, ε, Z0) Ⱶ(q4, ε)

Lecture Delivered by Surya Narayan Prasad 108


Working of Pushdown Automata …
● Let the input string be “aaaabb”.
● δ(q0, aaaabb, Z0) Ⱶ(q1, aZ0)
● δ(q1, aaabb, aZ0) Ⱶ(q1, aaZ0)
● δ(q1, aabb, aaZ0) Ⱶ(q1, aaaZ0)
● δ(q1, abb, aaaZ0) Ⱶ(q1, aaaaZ0)
● δ(q1, bb, aaaaZ0) Ⱶ(q2, aaaZ0)
● δ(q2, ϵb, aaaZ0) Ⱶ(q3, aaZ0)
● δ(q3, b, aaZ0) Ⱶ(q2, aZ0)
● δ(q2, ϵ, aZ0) Ⱶ(q3, Z0)
● δ(q3, ϵ, Z0) Ⱶ(q4, ϵ)

Lecture Delivered by Surya Narayan Prasad 109


Working of Pushdown Automata …
● The following transition table represents the same
Transition Transition Function used
δ(q0, aaaaaabbb,Z0) → δ(q1, aaaaabbb,aZ0) δ(q0, a, Z0) Ⱶ(q1, aZ0)
δ(q1, aaaaabbb,aZ0) → δ(q1, aaaabbb,aaZ0) δ(q1, a, a) Ⱶ(q1, aa)
δ(q1, aaaabbb,aaZ0) → δ(q1, aaabbb,aaaZ0) δ(q1, a, a) Ⱶ(q1, aa)
δ(q1, aaabbb,aaaZ0) → δ(q1, aabbb,aaaaZ0) δ(q1, b, a) Ⱶ(q2, a)
δ(q1, aabbb,aaaaZ0) → δ(q1, abbb,aaaaaZ0) δ(q2, b, a) Ⱶ(q3, ε)
δ(q1, abbb,aaaaaZ0) → δ(q1, bbb,aaaaaaZ0) δ(q3, b, a) Ⱶ(q2, a)
δ(q1, bbb,aaaaaaZ0) → δ(q2, bb,aaaaaZ0) δ(q2, b, a) Ⱶ(q3, ε)
δ(q2, bb,aaaaaZ0) → δ(q3, bb,aaaaZ0) δ(q3, b, a) Ⱶ(q2, a)

Lecture Delivered by Surya Narayan Prasad 110


Working of Pushdown Automata …
● The following transition table represents the same …
Transition Transition Function used
δ(q3, bb,aaaaZ0) → δ(q2, b,aaaZ0)
δ(q2, b,aaaZ0) → δ(q3, b,aaZ0)
δ(q3, b,aaZ0) → δ(q2, b,aZ0)
δ(q2, b,aZ0) → δ(q3, ε,Z0) δ(q2, b, a) Ⱶ(q3, ε)
δ(q3, ε,Z0) → δ(q4, ε, ε) (q3, ε,Z0) Ⱶ(q4, ε)

Lecture Delivered by Surya Narayan Prasad 111


Working of Pushdown Automata …
● The following transition graph represents the same

a,a/aa

a,Z0/aZ0 b,a/a b,a/ε ε,Z0/ε


q0 q1 q2 q3 q4

b,a/a

Lecture Delivered by Surya Narayan Prasad 112


Transition in PDA
● When an element is pushed to stack
● Suppose, the current stack symbol is Z1 and the current
input symbol is a.
● After reading the reading of symbol ‘a’, Z2 is to be pushed
into the stack. This Z2 can be a itself or cannot be.
● The current state is q0.
● Then δ can be written as δ(current state, current I/P
String, CurrentStackTop) Ⱶ (next state, StringLeft,
NewtopPrevioustop)
● δ(q0, aaaabb, Z0) Ⱶ (q1, aaabb, aZ0)
Lecture Delivered by Surya Narayan Prasad 113
Transition of PDA …
● When an element is popped from stack
● If a is the input symbol on state q0 with stack top Z0.
● Z0 is popped after the processing of symbol a and next
state is q1.
● Then, the transition will be written as δ(current state,
current I/P String, Currentstacktop) Ⱶ (next state,
StringLeft, Previousstacktop) i.e. δ(q0,a, Z0) Ⱶ (q1,ϵ,ϵ)

Lecture Delivered by Surya Narayan Prasad 114


Functioning of δ(Transition Function)
● When an element is pushed to stack
● Suppose, the current stack symbol is Z1 and the current
input symbol is a.
● After reading the reading of symbol ‘a’, Z2 is to be pushed
into the stack. This Z2 can be a itself or cannot be.
● The current state is q0.
● Then δ can be written as δ(current state, current I/P,
CurrentStackTop) Ⱶ (next state, NewtopPrevioustop)
● δ(q0, a, Z0) Ⱶ (q1, a Z0)

Lecture Delivered by Surya Narayan Prasad 115


Functioning of δ …
● When an element is popped from stack
● If a is the input symbol on state q0 with stack top Z0.
● Z0 is popped after the processing of symbol a and next
state is q1.
● Then, the transition will be written as δ(current state,
current I/P, Currentstacktop) Ⱶ (next state,
Previousstacktop) i.e. δ(q0,a, Z0) Ⱶ (q1, ϵ)

Lecture Delivered by Surya Narayan Prasad 116


Functioning of δ …
● No Change in the stack element
● Ifnothing is pushed or popped from stack then the δ will
be written as δ(current state, current i/p, stack top) =
(new state, stack top) i.e. δ(q4, ϵ, Z0) = (q4, Z0).

Lecture Delivered by Surya Narayan Prasad 117


Types of Pushdown Automata
● Deterministic
Pushdown Automata
● Non – Deterministic Pushdown Automata

Lecture Delivered by Surya Narayan Prasad 118


Types of Pushdown Automata: Deterministic
●A Deterministic Pushdown Automation is the one for which
every input string has a unique path through the machine.
● A pushdown automaton (Q, Σ, τ, δ, q0, Z, F) is deterministic if
● δ(q, a, Z) is either empty or single move.
● δ(q, ε, Z) != φ means δ(q, a, z) = φ for each a ϵ Σ.

Lecture Delivered by Surya Narayan Prasad 119


Types of Pushdown Automata: Non –
Deterministic
● Non Deterministic Pushdown Automaton are equivalent to
Context free Grammars (CFGs) and are more powerful than
deterministic one.
● Non Deterministic Pushdown Automaton is the one for
which, at certain time , we may have to select a particular
path among all possible paths i.e. for particular path we have
two or more transitions to go to next state.

Lecture Delivered by Surya Narayan Prasad 120


Auxiliary Pushdown Automata
● Auxiliary Pushdown Automata are the pushdown automata
with two way input and additional general purpose storage.
● The model of an auxiliary pushdown automaton is
● A read only input tape, with end symbols φ, $
● A finite state control
● A read – write storage tape of length S(n), where n is the
length of the input string ω.
● A stack i.e. pushdown store.

Lecture Delivered by Surya Narayan Prasad 121


Auxiliary Pushdown Automata
● Auxiliary Pushdown Automata are the pushdown automata
with two way input and additional general purpose storage.
● The model of an auxiliary pushdown automaton is
● A read only input tape, with end symbols φ, $
● A finite state control
● A read – write storage tape of length S(n), where n is the
length of the input string ω.
● A stack i.e. pushdown store.

Lecture Delivered by Surya Narayan Prasad 122


Two Stack Pushdown Automata
● Ifwe add one extra stack to a finite automaton, (definitely)
the power of finite automation increases.
● The class of 2 stack automation is equivalent to the class of
Turing Machine.

Lecture Delivered by Surya Narayan Prasad 123


Two Stack Pushdown Automata …
● The initial state of the PDA M is given as follows
ϵ ϵ 0 0 0 0 1 1 1 1 ϵ ϵ
1
1
1
0 1
δ(q2, ϵ, Z0)→(qf,ϵ, ϵ) Null Transition

Pushdown Store
0 0
0 0


0 0
ϵ 0
Stack1 Stack2
Lecture Delivered by Surya Narayan Prasad 124
Closure Properties of Context Free Language
Context free Languages are closed under the following
properties
● Union
● Concatenation
● Kleene Closure0n1n= 01,0011,000111 …
● Substitution
● Homomorphism
● Reverse Homomorphism

Lecture Delivered by Surya Narayan Prasad 125


Closure Properties of Context Free Language

Context free Languages are not closed under the following
properties
● Intersection
● Complementation L1, L2 →L3 =L1∪ L2 → L1’= L3-L1

Lecture Delivered by Surya Narayan Prasad 126


Properties of Context Free Language
● Every regular language is context free because it can be
described by a regular grammar.
● The intersection of a context free language and a regular
language is always context free.
● There exists context sensitive language, which are not
context free.
● To prove that a given language is not context free we can
take use of the pumping lemma for context free languages.

Lecture Delivered by Surya Narayan Prasad 127


Ambiguity
● Ambiguity is defined as the ability of being open to more than
one interpretation.
● Ambiguity is the existence of doubtfulness.
● Ambiguity is the existence of uncertainty.
● Ambiguity is defined as a statement or sentence or event or
scenario that could be interpreted in more than one possible way
of interpretation.it is up to the listener or reader to determine
what the true interpretation could be. There are some
statements which may be ambiguous when said alone but with
additional information, the ambiguity could be removed

Lecture Delivered by Surya Narayan Prasad 128


Ambiguous Grammar
●A grammar is said to be ambiguous, iff there exists two or
more derivation trees from a string ‘w’.
● The two more derivation trees can be two or more distinct
left most derivation tree or two more distinct right
derivation tree.

Lecture Delivered by Surya Narayan Prasad 129


Ambiguous Grammar …
● Considering the CFG G having productions S → S + S |a, then
the string a + a + a has two left most derivations
● S → S + S → S + S + S → a + S + S → a + a + S → a + a +a
● S → S + S → a + S → a + S + S → a + a + S → a + a + a.
● The corresponding derivation trees are given below

Lecture Delivered by Surya Narayan Prasad 130


Ambiguous Grammar …
S S

S + S S + S

S + S a a S + S

a a a a

Lecture Delivered by Surya Narayan Prasad 131


Inherently Grammar
●Acontext free language CFL for which every context free
grammar CFG is ambiguous, is said to be an inherently
ambiguous context free language.

Lecture Delivered by Surya Narayan Prasad 132


Types of Normal Form
● Chomsky Normal Form
● Greibach Normal Form

Lecture Delivered by Surya Narayan Prasad 133


Chomsky Normal Form
● Chomsky Normal Form
● There is a restriction on the length of RHS i.e. the
elements in RHS are either of two variable or one
terminal.
● The general form is S → AB, S →a, where S, A, B ϵ V and a
ϵ Σ.

Lecture Delivered by Surya Narayan Prasad 134


Chomsky Normal Form …
● Convertthe given grammar into corresponding Chomsky
Normal Form (CNF)
● S →aAD
● A →aB | bAB
● B →b
● D →d

Lecture Delivered by Surya Narayan Prasad 135


Chomsky Normal Form …
● Convertthe given grammar into corresponding Chomsky
Normal Form (CNF)
● S →aAD
● A →aB | bAB
● B →b
● D →d
● S →aAD or S →XD
● X →YA
● Y →a

Lecture Delivered by Surya Narayan Prasad 136


Greibach Normal Form
● Greibach Normal Form
● There is a restriction on the nature of elements of RHS i.e.
RHS productions are either a terminal or a terminal
followed by variables.

Lecture Delivered by Surya Narayan Prasad 137

You might also like