1 of 61

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

2 of 61

Topics to be covered

  • Why pushdown Automata?
  • Definition: PDA
  • Acceptance by PDA
  • Design PDA
  • CFG to PDA
  • PDA to CFG
  • Intersection and complement of CFL
  • Pumping lemma for CFG

Unit – 4 : Pushdown Automata, CFL & NCFL

Darshan Institute of Engineering & Technology

2

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

2

3 of 61

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

4 of 61

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

5 of 61

Pushdown Automata

  • A pushdown Automata is essentially a finite Automata with a stack data structure.

  • A PDA can write an unbounded no. of symbols on the stack and read these symbols later.
  • Writing a symbol on to the stack is called “PUSH” operation.
  • Removing a symbol off the stack is called “POP” operation.

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

6 of 61

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

7 of 61

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

8 of 61

Deterministic PDA

  •  

Unit – 4 : Pushdown Automata, CFL & NCFL

Darshan Institute of Engineering & Technology

8

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

8

9 of 61

Applications of PDA

  • A pushdown automata is a way to implement a context free grammar.
  • PDA is used in parser design for syntactic analysis.

Unit – 4 : Pushdown Automata, CFL & NCFL

Darshan Institute of Engineering & Technology

9

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

9

10 of 61

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

11 of 61

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

12 of 61

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

13 of 61

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

14 of 61

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

15 of 61

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

16 of 61

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

17 of 61

Exercise: Design PDA

  1. Design PDA for anbncmdm , n,m>=1
  2. Design PDA for anbmcmdn , n,m>=1
  3. Design PDA for an+mbncm , n,m>=1

Unit – 4 : Pushdown Automata, CFL & NCFL

Darshan Institute of Engineering & Technology

17

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

17

18 of 61

Design PDA for palindrome with middle symbol c.

  • Design a PDA for following CFG.

S🡪aSa/bSb/c

  • Design PDA for L={xcxr/x∈{a,b}*}. The string in L are odd length palindromes over {a,b}
  • Strings accepted in the language are:
  • aba c aba
  • aaa c aaa
  • bab c bab
  • ab c ba

Unit – 4 : Pushdown Automata, CFL & NCFL

Darshan Institute of Engineering & Technology

18

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

18

19 of 61

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

20 of 61

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

21 of 61

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

22 of 61

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

23 of 61

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

24 of 61

Exercise

Trace the following string:

  1. bcb
  2. ab
  3. acaa

Unit – 4 : Pushdown Automata, CFL & NCFL

Darshan Institute of Engineering & Technology

24

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

24

25 of 61

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

26 of 61

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

27 of 61

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

28 of 61

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

29 of 61

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

30 of 61

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

31 of 61

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

32 of 61

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

33 of 61

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

34 of 61

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

35 of 61

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

36 of 61

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

37 of 61

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

38 of 61

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

39 of 61

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

40 of 61

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

41 of 61

Steps to convert CFG to PDA

  • From given CFG G=(V,Σ,S,P), we can construct a PDA.
  • The PDA’s δ is given by :
    1. For each non terminal A, include a transition

Include a transition δ(q, 𝜖, A)🡪{(q, α)|A🡪 α is a production in G}

    • For each terminal a, include a transition

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

42 of 61

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

43 of 61

Exercise: CFG to PDA

  1. Given a CFG , G =( {S,A,B},{0,1},P,S) with P as follows:

S 🡪 0B| 1A

A 🡪 0S|1AA|0

B 🡪 1S| 0BB | 1

  1. Design a PDA M corresponding to CFG:

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

44 of 61

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

45 of 61

Rule to convert PDA to CFG

  1. Add the following production for the start symbol S.

S🡪[q0 z qi]

q0 initial state

z initial stake symbol

qi ∈ Q

  1. For 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]

Unit – 4 : Pushdown Automata, CFL & NCFL

Darshan Institute of Engineering & Technology

45

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

45

46 of 61

Rule to convert PDA to CFG

  1. 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]

Unit – 4 : Pushdown Automata, CFL & NCFL

Darshan Institute of Engineering & Technology

46

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

46

47 of 61

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

48 of 61

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

49 of 61

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

50 of 61

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

51 of 61

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

52 of 61

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

53 of 61

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

54 of 61

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

55 of 61

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

56 of 61

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

57 of 61

Intersection and complement of CFL

  • Theorem:-There are CFLs L1 and L2 so that L1∩ L2 is not a CFL, and there is a CFL L so that L’ is not a CFL.
  • We observed that

L= { aibjck| i < j and i < k }

  • is not context-free. However, although no PDA can test both conditions i < j and i< k simultaneously, it is easy enough to build two PDAs that test the conditions separately. In other words, although the intersection L of the two languages

L1 = {a i bjck | i < j}

and

L2 = {aibjck | i < k}

  • is not a CFL, both languages themselves are.

Unit – 4 : Pushdown Automata, CFL & NCFL

Darshan Institute of Engineering & Technology

57

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

57

58 of 61

Intersection and complement of CFL

  • Another way to verify that L1 is a CFL is to check it is generated by the grammar with productions

S🡪ABC A🡪aAb|˄ B🡪bB|b C🡪cC|˄

  • Similarly, L2is generated by the CFG with productions

S🡪AC A🡪aAc|B B🡪bB|˄ C🡪cC|c

  • The second statement in the theorem follows from the first and the formula

L1∩ L2 =( L1’U L2’)’

  • If complements of CFLs were always CFLs, then for any CFLs L1 and L2, the language L1’and L2’ would be CFLs, so would their union, and so would its complement. We know now that this is not the case.

Unit – 4 : Pushdown Automata, CFL & NCFL

Darshan Institute of Engineering & Technology

58

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

58

59 of 61

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

60 of 61

Pumping lemma for CFG

  • Suppose L is a context-free language. Then there is an integer n so that for every u ∈ L with |u| ≥ n, there are strings v, w, x, y, and z satisfying,

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

61 of 61

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