Languages and Finite Automata

Download Report

Transcript Languages and Finite Automata

DPDA
Deterministic PDA
Prof. Busch - LSU
1
Deterministic PDA: DPDA
Allowed transitions:
q1
q1
a, b  w
, b  w
q2
q2
(deterministic choices)
Prof. Busch - LSU
2
Allowed transitions:
a, b  w1
 , b  w1
q2
q1
q2
q1
a , c  w2
 , c  w2
q3
q3
(deterministic choices)
Prof. Busch - LSU
3
Not allowed:
a, b  w1
 , b  w1
q2
q1
q2
q1
a , b  w2
a , b  w2
q3
q3
(non deterministic choices)
Prof. Busch - LSU
4
DPDA example
L( M )  {a b : n  0}
n n
a,   a
b, a  
a,


a
b,
a



,
$

$
q3
q2
q0
q1
Prof. Busch - LSU
5
Definition:
A language L is deterministic context-free
if there exists some DPDA that accepts it
Example:
The language
L( M )  {a b : n  0}
n n
is deterministic context-free
Prof. Busch - LSU
6
Example of Non-DPDA (PDA)
L(M )  {vv : v {a, b} }
R
a,   a
b,   b
q0
*
a, a  
b, b  
,   
q1
Prof. Busch - LSU
, $  $
q2
7
Not allowed in DPDAs
a,   a
b,   b
q0
a, a  
b, b  
,   
q1
Prof. Busch - LSU
, $  $
q2
8
PDAs
Have More Power than
DPDAs
Prof. Busch - LSU
9
It holds that:
Deterministic
Context-Free
Languages
(DPDA)

Context-Free
Languages
PDAs
Since every DPDA is also a PDA
Prof. Busch - LSU
10
We will actually show:
Deterministic
Context-Free
Languages
(DPDA)

Context-Free
Languages
(PDA)
L
L
We will show that there exists
a context-free language L which is not
accepted by any DPDA
Prof. Busch - LSU
11
The language is:
L  {a b }  {a b }
n n
n 2n
n0
We will show:
• L is context-free
• L is not deterministic context-free
Prof. Busch - LSU
12
L  {a b }  {a b }
n n
Language
n 2n
L is context-free
Context-free grammar for
S  S1 | S2
L:
{a nbn }  {a nb2n }
S1  aS1b | 
S2  aS2bb | 
Prof. Busch - LSU
n n
{a b }
n 2n
{a b }
13
Theorem:
The language
L  {a b }  {a b }
n n
n 2n
is not deterministic context-free
(there is no DPDA that accepts
Prof. Busch - LSU
L)
14
Proof: Assume for contradiction that
L  {a b }  {a b }
n n
n 2n
is deterministic context free
Therefore:
there is a DPDA
M that accepts L
Prof. Busch - LSU
15
DPDA
M with L( M )  {a b }  {a b }
n n
accepts
n 2n
n n
a b
n n
a b
b
accepts
n
n 2n
a b
Prof. Busch - LSU
16
DPDA
M with L( M )  {a b }  {a b }
n n
n 2n
Such a path exists due to determinism
M
n n
a b
b
Prof. Busch - LSU
n
17
Fact 1:
n n n
The language {a b
is not context-free
c }
Context-free languages
a nb n
Regular languages
a *b *
(we will prove this at a later class using
pumping lemma for context-free languages)
Prof. Busch - LSU
18
Fact 2:
The language L  {a
is not context-free
n n n
b c }
( L  {a b }  {a b })
n n
n 2n
(we can prove this using pumping lemma
for context-free languages)
Prof. Busch - LSU
19
We will construct a PDA that accepts:
L  {a b c }
n n n
( L  {a b }  {a b })
n n
n 2n
which is a contradiction!
Prof. Busch - LSU
20
DPDA
L( M )  {a b }  {a b }
n n
M
a nb n
Modify
DPDA
M
bn
Replace
with c
M
n 2n
b
L( M )  {a nc n }  {a nc 2n }
a nc n
cn
Prof. Busch - LSU
21
A PDA that accepts
L  {a b c }
n n n
Connect the final states of M
with the final states of M 
M
a nbn
bn

M
a nc n

cn
Prof. Busch - LSU
22
L  {a b c } is accepted by a PDA
n n n
Since
it is context-free
Contradiction!
(since
L  {a b c } is not context-free)
n n n
Prof. Busch - LSU
23
Therefore:
L  {a b }  {a b }
n n
n 2n
Is not deterministic context free
There is no DPDA that accepts it
End of Proof
Prof. Busch - LSU
24