meljun cortes automata lecture pushdown automata 2
TRANSCRIPT
-
8/21/2019 MELJUN CORTES Automata Lecture Pushdown Automata 2
1/20
Theory of Computation (With Automata Theory)
* Property of STI
Page 1 of 20
Pushdown Automata
PUSHDOWN AUTOMATA
Pushdown Automata
Introduction
• A regular expression cangenerate the strings of theregular language it represents.
• A context-free grammar cangenerate the strings of thecontext-free language itrepresents.
• A finite automaton recognizesregular languages.
• The machine that recognizescontext-free languages iscalled a pushdown automaton (PDA).
-
8/21/2019 MELJUN CORTES Automata Lecture Pushdown Automata 2
2/20
Theory of Computation (With Automata Theory)
* Property of STI
Page 2 of 20
Pushdown Automata
• A PDA is similar to an NFAexcept that it has access to astack.
Representation of an NFA:
NFA
0 1 1 0
Input String
-
8/21/2019 MELJUN CORTES Automata Lecture Pushdown Automata 2
3/20
Theory of Computation (With Automata Theory)
* Property of STI
Page 3 of 20
Pushdown Automata
• Representation of a PDA:
The stack follows a last-in,first-out (LIFO) structure.
PDA
a
b
a
b
Stack
0 1 1 0
Input String
-
8/21/2019 MELJUN CORTES Automata Lecture Pushdown Automata 2
4/20
Theory of Computation (With Automata Theory)
* Property of STI
Page 4 of 20
Pushdown Automata
• Operations that can be doneon the stack are push (add asymbol to the top of the stack)and pop (remove a symbolfrom the top of the stack).
• State transitions in a PDAdepend on the current state,the incoming input symbol,and the symbol at the top of
the stack.
• The stack can give additionalmemory beyond what isavailable in an NFA (as
represented by the states).
• PDAs are more powerful thanNFAs because they canrecognize some non-regular
languages.
-
8/21/2019 MELJUN CORTES Automata Lecture Pushdown Automata 2
5/20
Theory of Computation (With Automata Theory)
* Property of STI
Page 5 of 20
Pushdown Automata
Case Study:
Consider the non-regularlanguage L1 = {0
n1n n ≥ 0}.There is no NFA that can
recognize this language but aPDA can be constructed torecognize it.
PDA Operation:
1. Read each symbol of theinput string.
2. While the input is a 0, pushit onto the stack.
3. While the input symbol is a1, pop a 0 off the stack.4. If there is no more input
symbol and the stack isempty, the input string is
accepted.
-
8/21/2019 MELJUN CORTES Automata Lecture Pushdown Automata 2
6/20
Theory of Computation (With Automata Theory)
* Property of STI
Page 6 of 20
Pushdown Automata
Formal Definition of Pushdown Automata
• A pushdown automaton is a 6-tuple (Q, , , , q0, F ), whereQ, , , and F are all finitesets, and
1. Q is the set of states,
2. is the input alphabet,
3. is the stack alphabet,
4. is the transition function,
5. q0 Q and is the startstate, and
6. F Q and is the set of final
states.
-
8/21/2019 MELJUN CORTES Automata Lecture Pushdown Automata 2
7/20
Theory of Computation (With Automata Theory)
* Property of STI
Page 7 of 20
Pushdown Automata
• The stack alphabet is the setof symbols that can be pushedonto the stack. It may or maynot be the same as the inputstring alphabet .
• Transitions in a PDA
In an NFA, transitions are
represented by:
(qi , 0) = q j
This equation indicates that if
the current state is state qi andthe input is 0, the NFA goes tostate q j . State transitions aretherefore determined by thecurrent state and the input
symbol.
-
8/21/2019 MELJUN CORTES Automata Lecture Pushdown Automata 2
8/20
Theory of Computation (With Automata Theory)
* Property of STI
Page 8 of 20
Pushdown Automata
In a PDA, transitions arerepresented by:
(qi
, 0, a) = (q j
, b)
This equation indicates that if the current state is state qi andthe input symbol is 0, and the
symbol at the top of the stackis a, the PDA goes to state q j and pushes the symbol b ontothe stack.
State transitions are thusdetermined by the currentstate, the input symbol, andthe symbol at the top of thestack.
-
8/21/2019 MELJUN CORTES Automata Lecture Pushdown Automata 2
9/20
Theory of Computation (With Automata Theory)
* Property of STI
Page 9 of 20
Pushdown Automata
• PDA State Diagrams
PDA state diagrams are similar to NFA state diagrams exceptfor the labels of the transition
edges.
Example:
The label a, b → c means thatif the input symbol is a and thesymbol read from the top of the stack is b, then the PDAgoes to state q j and it pushes
the symbol c unto the stack.
q j
a, b → c
q i
-
8/21/2019 MELJUN CORTES Automata Lecture Pushdown Automata 2
10/20
Theory of Computation (With Automata Theory)
* Property of STI
Page 10 of 20
Pushdown Automata
Take note that reading thesymbol at the top of the stackimplies a pop operation. Thelabel a, b → c implies that thesymbol b was popped off thestack.
Furthermore, any of thesymbols a, b, c in the givenlabel can also be the emptystring .
1. If a = , the PDA makesthe transition without anyinput symbol.
2. If b = , the PDA makes
the transition withoutreading any symbol fromthe stack.
3. If c = , the PDA does notpush any symbol onto the
stack.
-
8/21/2019 MELJUN CORTES Automata Lecture Pushdown Automata 2
11/20
Theory of Computation (With Automata Theory)
* Property of STI
Page 11 of 20
Pushdown Automata
• In order for the PDA todetermine if the stack isempty, a special symbol will bedesignated as the stack emptysymbol.
This symbol will be pushedonto the stack every time acomputation is started.
The symbol that will be usedhere will be the dollar sign ($ ).
So, any time the PDA seesthat the symbol at the top of the stack is $ , then the stack isconsidered empty.
-
8/21/2019 MELJUN CORTES Automata Lecture Pushdown Automata 2
12/20
Theory of Computation (With Automata Theory)
* Property of STI
Page 12 of 20
Pushdown Automata
• Sample Transitions
q j
0, a → b
q i
a
x
y
$
stack before
transition
b
x
y
$
stack after
transition
top of thestack
top of thestack
q j
0, a → a
q i
a
x
y
$
stack beforetransition
a
x
y
$
stack aftertransition
top of thestack
top of thestack
-
8/21/2019 MELJUN CORTES Automata Lecture Pushdown Automata 2
13/20
Theory of Computation (With Automata Theory)
* Property of STI
Page 13 of 20
Pushdown Automata
q j
0, → b
q i
a
x
y
$
stack beforetransition
a
x
y
$
stack aftertransition
b
top of thestack
top of thestack
q j
0, a →
q i
a
x
y
$
stack beforetransition
x
y
$
stack aftertransition
top of thestack
top of thestack
-
8/21/2019 MELJUN CORTES Automata Lecture Pushdown Automata 2
14/20
Theory of Computation (With Automata Theory)
* Property of STI
Page 14 of 20
Pushdown Automata
• It was mentioned earlier that aPDA can make a state
transition without any inputsymbol.
This implies that PDAs arenondeterministic.
q j
0, →
q i
ax
y
$
stack beforetransition
x
y
$
stack aftertransition
top of the
stacktop of the
stacka
-
8/21/2019 MELJUN CORTES Automata Lecture Pushdown Automata 2
15/20
Theory of Computation (With Automata Theory)
* Property of STI
Page 15 of 20
Pushdown Automata
• Continuation of Case Study
The PDA P 1 that canrecognize the non-regular
language L1 = {0n1n n ≥ 0} is:
q 0
q 1 q 2
q 3
, → $
0, → 0
1, 0 →
1, 0 →
, $ →
-
8/21/2019 MELJUN CORTES Automata Lecture Pushdown Automata 2
16/20
Theory of Computation (With Automata Theory)
* Property of STI
Page 16 of 20
Pushdown Automata
The given PDA can be formallydefined as P 1 = (Q, , , , q0,F ) where:
1. Q = {q0, q1, q2, q3}
2. = {0, 1}
3. = {0, $}
4. q0 is the start state.
5. F = {q0, q3}
-
8/21/2019 MELJUN CORTES Automata Lecture Pushdown Automata 2
17/20
Theory of Computation (With Automata Theory)
* Property of STI
Page 17 of 20
Pushdown Automata
6. The transition function isgiven by:
Input StackCurrent State
q0 q1 q2 q3
0
0
$
(q 1, 0)
1
0 (q 2, ) (q 2, )
$
0$ (q 3, )
(q 1, $)
-
8/21/2019 MELJUN CORTES Automata Lecture Pushdown Automata 2
18/20
Theory of Computation (With Automata Theory)
* Property of STI
Page 18 of 20
Pushdown Automata
• Example 2:
The PDA P 2 that canrecognize the non-regular
language L2 = {ww R w {0,1}*} is:
q 0
q 1 q 2
q 3
, → $
0, → 0
, →
0, 0→
, $→
1, → 1 1, 1→
-
8/21/2019 MELJUN CORTES Automata Lecture Pushdown Automata 2
19/20
Theory of Computation (With Automata Theory)
* Property of STI
Page 19 of 20
Pushdown Automata
• Example 3:
The PDA P 3 that canrecognize the non-regular
language L3 = {ai b j c k i , j , k 0and i = j or i = k } is:
q 0
, →q 1 q 4
, →q 5 q 6
, $ →
a, → a b, → c, a →
q 2 q 3
,
→
, $ →
, → $
b, a → c, →
-
8/21/2019 MELJUN CORTES Automata Lecture Pushdown Automata 2
20/20
Theory of Computation (With Automata Theory)
* Property of STI Pushdown Automata
• Exercises:
Construct a PDA that canrecognize the language L4 ={w w is composed of an equalnumber of 0s and 1s}.
Construct a PDA that canrecognize the language L5 ={02n1n n ≥ 1}.