Prof. Dixita B. Kagathara
2160704
Theory of Computation
Unit-4
Pushdown Automata, CFL & NCFL
dixita.kagathara@darshan.ac.in
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
1
Topics to be covered
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
2
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
2
Why Pushdown Automata?
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
3
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
3
Why Pushdown Automata?
Not Possible??
a
b
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
4
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
4
Pushdown Automata
Finite Stack Control
Input
Accept | Reject
Stack
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
5
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
5
Definition of PDA
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
6
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
6
Acceptance by PDA
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
7
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
7
Deterministic PDA
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
8
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
8
Applications of PDA
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
9
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
9
Design DPDA for L={anbn|a,b ∈ Ʃ, n≥0}
anbn
If n=3 then
a3b3
= a a a b b b
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
10
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
10
How to Represent PDA?
a, z0|az0
Move No | State | Input | Stack Symbol | Move(s) |
| | | | |
| | | | |
| | | | |
a, a | aa
b, a | ^
Input symbol, stack symbol | PUSH/POP
FIRST 2 SYMBOLS OF THE STACK
^
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
11
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
11
Design DPDA for L={anbn|a,b ∈ Ʃ, n≥0}
a, z0|az0
Move No | State | Input | Stack Symbol | Move(s) |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
^,z0 | z0
a, a | aa
b, a | ^
b, a | ^
^,z0 | z0
| |
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
12
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
12
Design DPDA for same no. of a’s & b’s.
Move No | State | Input | Stack Symbol | Move(s) |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
a, z0|az0
a, a | aa
b, z0|bz0
b, b | bb
a, b|^
b, a|^
^,z0 | z0
| |
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
13
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
13
Design PDA for {anbn+m cm | n,m>=1}
an bn+m cm
= an bn bm cm
If n=2 and m=3 then
= a2 b2 b3 c3
= aa bb bbb ccc
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
14
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
14
Design PDA for {anbn+m cm | n,m>=1}
Move No | State | Input | Stack Symbol | Move(s) |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
a, a| aa
a, z0| az0
b, a| ^
b, a| ^
b, z0| bz0
| | | | |
b, b| bb
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
15
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
15
Design PDA for {anbn+m cm | n,m>=1}
Move No | State | Input | Stack Symbol | Move(s) |
| | | | |
| | | | |
| | | | |
| |
c, b| ^
c, b| ^
^, z0| z0
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
16
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
16
Exercise: Design PDA
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
17
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
17
Design PDA for palindrome with middle symbol c.
S🡪aSa/bSb/c
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
18
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
18
Design PDA for palindrome with middle symbol c.
a b a c a b a
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
19
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
19
Design PDA for palindrome with middle symbol c.
a, z0|az0
a, a | aa
b, z0|bz0
b, b | bb
b, a | ba
a, b | ab
Move No | State | Input | Stack Symbol | Move(s) |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
20
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
20
Design PDA for palindrome with middle symbol c.
c,b | b
c,a | a
c,z0 | z0
Move No | State | Input | Stack Symbol | Move(s) |
| | | | |
| | | | |
| | | | |
a, z0|az0
a, a | aa
b, z0|bz0
b, b | bb
b, a | ba
a, b | ab
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
21
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
21
Design PDA for palindrome with middle symbol c.
b, b | ^
a, a | ^
^,z0 | z0
Move No | State | Input | Stack Symbol | Move(s) |
| | | | |
| | | | |
| |
| | | | |
c,b | b
c,a | a
c,z0 | z0
a, z0|az0
a, a | aa
b, z0|bz0
b, b | bb
b, a | ba
a, b | ab
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
22
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
22
String Tracing
Move No | Resulting State | Unread Input | Stack |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
b, b | ^
a, a | ^
^,z0 | z0
c,b | b
c,a | a
c,z0 | z0
a, z0|az0
a, a | aa
b, z0|bz0
b, b | bb
b, a | ba
a, b | ab
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
23
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
23
Exercise
Trace the following string:
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
24
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
24
Design PDA for {aibjck | i,j,k>=1 & j=i or j=k}
Move No | State | Input | Stack Symbol | Move(s) |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
a, a| aa
a, z0| az0
b, a| ^
b, a| ^
c, z0| z0
c, z0| z0
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
25
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
25
Design PDA for {aibjck | i,j,k>=1 & j=i or j=k}
Move No | State | Input | Stack Symbol | Move(s) |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
^, z0| z0
a, z0| z0
a, z0| z0
b, b| bb
b,z0| bz0
c, b| ^
c, b| ^
a, a| aa
a, z0| az0
b, a| ^
b, a| ^
c, z0| z0
c, z0| z0
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
26
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
26
Design PDA for {aibjck | i,j,k>=1 & j=i or j=k}
Move No | State | Input | Stack Symbol | Move(s) |
| | | | |
^, z0| z0
a, z0| z0
a, z0| z0
b, b| bb
b,z0| bz0
c, b| ^
c, b| ^
^, z0| z0
| |
J=
j=i
J=
j=k
i=j
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
27
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
27
Design DPDA for L={anb2n|a,b ∈ Ʃ, n≥0}
anb2n
If n=1 then
a1b2
= a b b
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
28
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
28
Design DPDA for L={anb2n|a,b ∈ Ʃ, n≥0}
a, z0|aa
Move No | State | Input | Stack Symbol | Move(s) |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
^,z0 | z0
a, a | aa
b, a | ^
b, a | ^
^,z0 | z0
| |
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
29
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
29
Design PDA for even odd length palindrome (Nondeterministic)
a, z0|az0
a, a | aa
b, z0|bz0
b, b | bb
b, a | ba
a, b | ab
Move No | State | Input | Stack Symbol | Move(s) |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
b,a | a
a,b | b
a,a | a
b, z0| z0 z0
a, z0| z0
b,b | b
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
30
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
30
Design PDA for even odd length palindrome
Move No | State | Input | Stack Symbol | Move(s) |
| | | | |
| | | | |
| | | | |
^,b | b
^,a | a
^,z0 | z0
a, z0|az0
a, a | aa
b, z0|bz0
b, b | bb
b, a | ba
a, b | ab
a,z0 | z0
b,z0|z0
b,a | a
a,b | b
a,a | a
b,b | b
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
31
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
31
Design PDA for even odd length palindrome
b, b | ^
a, a | ^
^,z0 | z0
Move No | State | Input | Stack Symbol | Move(s) |
| | | | |
| | | | |
| |
| | | | |
^,b | b
^,a | a
^,z0 | z0
a, z0|az0
a, a | aa
b, z0|bz0
b, b | bb
b, a | ba
a, b | ab
b,b | b
a,b | b
a,a | a
a,z0|z0
b,z0|z0
b,a | a
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
32
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
32
Design DPDA for grammar S🡪SS|[S]|{S}|˄
[, [|[[
[, { | [{
{, [ | {[
{, { | {{
Move No | State | Input | Stack Symbol | Move(s) |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
[, z0|[z0
{, z0|{z0
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
33
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
33
Design DPDA for grammar S🡪SS|[S]|{S}|˄
}, { | ^
], [ | ^
^,z0 | z0
Move No | State | Input | Stack Symbol | Move(s) |
| | | | |
| | | | |
| | | | |
{, { | {{
| |
[, [|[[
[, { | [{
{, [ | {[
{, { | {{
[, z0|[z0
{, z0|{z0
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
34
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
34
Design DPDA for grammar S🡪SS|[S]|{S}|˄
}, { | ^
], [ | ^
^,z0 | z0
[, [|[[
[, { | [{
{, [ | {[
{, { | {{
[, z0|[z0
{, z0|{z0
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
35
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
35
Design PDA to accept string with more a’s than b’s.
a, a | aa
a, z0|az0
Move No | State | Input | Stack Symbol | Move(s) |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
b, b | bb
^, a | a
b, a | ^
a, b | ^
b, z0| bz0
| | | | |
| |
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
36
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
36
Design PDA for twice many a’s as b’s
a, z0| z0
b, z0|yz0
b, y|yy
a, z0| xz0
Move No | State | Input | Stack Symbol | Move(s) |
| | | | |
| | | | |
| | | | |
| | | | |
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
37
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
37
Design PDA for twice many a’s as b’s
a, z0| z0
a, x| x
b, y|yy
b, z0|yz0
b, x|^
b, z0|yz0
b, y|yy
a, z0| xz0
a, x| xx
Move No | State | Input | Stack Symbol | Move(s) |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
38
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
38
Design PDA for twice many a’s as b’s
a, z0| z0
a, x| x
a, y| y
b, a| y
b, y|yy
b, z0|yz0
b, x|^
b, z0|yz0
b, y|yy
a, z0| xz0
a, x| xx
a, y| ^
b, x| ^
Move No | State | Input | Stack Symbol | Move(s) |
| | | | |
| | | | |
| | | | |
| | | | |
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
39
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
39
CFG to PDA
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
40
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
40
Steps to convert CFG to PDA
Include a transition δ(q, 𝜖, A)🡪{(q, α)|A🡪 α is a production in G}
Include a transition δ(q, a, a)🡪{(q, 𝜖)}
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
41
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
41
Example: CFG to PDA
Find PDA for following grammar:
S🡪0S1 | 00 | 11
The equivalent PDA, M is given by:
δ(q, 𝜖, S)= {(q, 0S1), (q, 00), (q,11)}
δ(q, 0, 0)={(q, 𝜖)}
δ(q, 1, 1)={(q, 𝜖)}
δ(q, 𝜖, A)🡪{(q, α)|A🡪 α is a production in G
δ(q, a, a)🡪{(q, 𝜖)}
Non Terminal
Terminal
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
42
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
42
Exercise: CFG to PDA
S 🡪 0B| 1A
A 🡪 0S|1AA|0
B 🡪 1S| 0BB | 1
I 🡪 a | b | Ia | Ib | I0 | I1
E 🡪 I | E * E | E + E | (E)
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
43
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
43
PDA to CFG
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
44
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
44
Rule to convert PDA to CFG
S🡪[q0 z qi]
q0 initial state
z initial stake symbol
qi ∈ Q
where qi, qj ∈ Q
a ∈ (Ʃ U ^)
B, C ∈ (┌ U ^)
Then for each q∈ Q, add the production
[qi, B, q]🡪a[qj, C, q]
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
45
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
45
Rule to convert PDA to CFG
where qi, qj ∈ Q
a ∈ (Ʃ U ^)
B, C1, C2 ∈ (┌ U ^)
Then for each p1, p2 ∈ Q, add the production
[qi, B, p1]🡪a[qj C1 p2] [p2 C2 p1]
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
46
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
46
Example: PDA to CFG
State | Input | Stack | New state | Stack |
q | 1 | z | q | xz |
q | 1 | x | q | xx |
q | ^ | x | q | ^ |
q | 0 | x | p | x |
p | 1 | x | p | ^ |
p | 0 | z | q | z |
Step 1: Add the production for the start symbol
S🡪[q z q]
S🡪[q z p]
S🡪[q0 z qi]
q0 initial state
z initial stack symbol
qi ∈ Q (all state)
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
47
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
47
Example: PDA to CFG
State | Input | Stack | New state | Stack |
q | 1 | z | q | xz |
q | 1 | x | q | xx |
q | ^ | x | q | ^ |
q | 0 | x | p | x |
p | 1 | x | p | ^ |
p | 0 | z | q | z |
Step 2: Add production for the δ( q, 1, z) 🡪(q ,xz)
[q z q]🡪1[q x q][q z q]
[q z q]🡪1[q x p][p z q]
[q z p]🡪1[q x q][q z p]
[q z p]🡪1[q x p][p z p]
[qi, B, p1]🡪a[qj C1 p2] [p2 C2 p1]
For transition of the form δ( qi, a, B) 🡪(qj,C1C2)
where qi, qj ∈ Q
a ∈ (Ʃ U ^)
B, C1, C2 ∈ (┌ U ^)
Then for each p1, p2 ∈ Q, add the production
[qi, B, p1]🡪a[qj C1 p2] [p2 C2 p1]
δ( qi, a, B) 🡪(qj,C1C2)
P1=q p2=q
P1=q p2=p
P1=p p2=q
P1=p p2=p
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
48
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
48
Example: PDA to CFG
State | Input | Stack | New state | Stack |
q | 1 | z | q | xz |
q | 1 | x | q | xx |
q | ^ | x | q | ^ |
q | 0 | x | p | x |
p | 1 | x | p | ^ |
p | 0 | z | q | z |
Step 3: Add production for the δ( q, 1, x) 🡪(q ,xx)
[q x q]🡪1[q x q][q x q]
[q x q]🡪1[q x p][p x q]
[q x p]🡪1[q x q][q x p]
[q x p]🡪1[q x p][p x p]
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
49
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
49
Example: PDA to CFG
State | Input | Stack | New state | Stack |
q | 1 | z | q | xz |
q | 1 | x | q | xx |
q | ^ | x | q | ^ |
q | 0 | x | p | x |
p | 1 | x | p | ^ |
p | 0 | z | q | z |
Step 4: Add the production for δ( q, ^, x) 🡪(q ,^)
[q x q]🡪^
state
stack
New state
input
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
50
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
50
Example: PDA to CFG
State | Input | Stack | New state | Stack |
q | 1 | z | q | xz |
q | 1 | x | q | xx |
q | ^ | x | q | ^ |
q | 0 | x | p | x |
p | 1 | x | p | ^ |
p | 0 | z | q | z |
Step 5: Add the production for δ( q, 0, x) 🡪(p ,x)
[q x q]🡪0 [p x q]
[q x p]🡪0 [p x p]
Each transition of the form δ( qi, a, B) 🡪(qj, C)
where qi, qj ∈ Q
a ∈ (Ʃ U ^)
B, C ∈ (┌ U ^)
Then for each q∈ Q, add the production
[qi, B, q]🡪a[qj, C, q]
δ( qi, a, B) 🡪(qj, C)
[qi, B, q]🡪a[qj, C, q]
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
51
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
51
Example: PDA to CFG
State | Input | Stack | New state | Stack |
q | 1 | z | q | xz |
q | 1 | x | q | xx |
q | ^ | x | q | ^ |
q | 0 | x | p | x |
p | 1 | x | p | ^ |
p | 0 | z | q | z |
Step 6: Add the production for δ( p, 1, x) 🡪(p ,^)
[p x p]🡪1
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
52
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
52
Example: PDA to CFG
State | Input | Stack | New state | Stack |
q | 1 | z | q | xz |
q | 1 | x | q | xx |
q | ^ | x | q | ^ |
q | 0 | x | p | x |
p | 1 | x | p | ^ |
p | 0 | z | q | z |
Step 7: Add the production for δ( p, 0, z) 🡪(q ,z)
[p z q]🡪0 [q z q]
[p z p]🡪0 [q z p]
δ( qi, a, B) 🡪(qj, C)
[qi, B, q]🡪a[qj, C, q]
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
53
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
53
Example: PDA to CFG
Step 8: Renaming variable name
The set of production can be written as:
S🡪A|B
A🡪1EA|1FC
B🡪1EB|1FD
E🡪1EE|1FG
F🡪1EF|1FH
E🡪^
E🡪0G
F🡪0H
H🡪1
C🡪0A
D🡪0B
Original name | New name |
[q z q] | A |
[q z p] | B |
[p z q] | C |
[p z p] | D |
[q x q] | E |
[q x p] | F |
[p x q] | G |
[p x p] | H |
Step1:
S🡪[q z q]
S🡪[q z p]
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
54
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
54
Example: PDA to CFG
Step 9: simplification of grammar
Symbol G is not available on left side of
grammar so, it can be eliminated.
S🡪A|B
A🡪1EA|1FC
B🡪1EB|1FD
E🡪1EE|^
F🡪1EF|1FH|0H
H🡪1
C🡪0A
D🡪0B
Original name | New name |
[q z q] | A |
[q z p] | B |
[p z q] | C |
[p z p] | D |
[q x q] | E |
[q x p] | F |
[p x q] | G |
[p x p] | H |
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
55
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
55
Intersection and complement of CFL (Non CFL)
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
56
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
56
Intersection and complement of CFL
L= { aibjck| i < j and i < k }
L1 = {a i bjck | i < j}
and
L2 = {aibjck | i < k}
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
57
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
57
Intersection and complement of CFL
S🡪ABC A🡪aAb|˄ B🡪bB|b C🡪cC|˄
S🡪AC A🡪aAc|B B🡪bB|˄ C🡪cC|c
L1∩ L2 =( L1’U L2’)’
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
58
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
58
Pumping lemma for CFG
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
59
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
59
Pumping lemma for CFG
u = vwxyz
|wy| > 0
|wxy| ≤ n
for every m ≥ 0, vwmxymz ∈ L
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
60
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
60
End of Unit - 4
Unit – 4 : Pushdown Automata, CFL & NCFL
Darshan Institute of Engineering & Technology
61
Theory of Computation (2160704)
Darshan Institute of Engineering & Technology
61