pushdown automata - wichita state universitysinha/teaching/fall15/cs720/slide/pda1.pdf · rationale...
TRANSCRIPT
Pushdown Automata
October 14, 2015
Pushdown Automata
Rationale
I CFG are specification mechanisms, i.e., a CFG generates acontext-free language.
I Pushdown-automata are recognizing mechanisms, i.e., a PDArecognizes a context-free language.
I CFG are like regular expressions and PDA are like FA.
Pushdown Automata
Rationale
I CFG are specification mechanisms, i.e., a CFG generates acontext-free language.
I Pushdown-automata are recognizing mechanisms, i.e., a PDArecognizes a context-free language.
I CFG are like regular expressions and PDA are like FA.
Pushdown Automata
Rationale
I CFG are specification mechanisms, i.e., a CFG generates acontext-free language.
I Pushdown-automata are recognizing mechanisms, i.e., a PDArecognizes a context-free language.
I CFG are like regular expressions and PDA are like FA.
Pushdown Automata
Rationale
I CFG are specification mechanisms, i.e., a CFG generates acontext-free language.
I Pushdown-automata are recognizing mechanisms, i.e., a PDArecognizes a context-free language.
I CFG are like regular expressions and PDA are like FA.
Pushdown Automata
A new type of computation model
I Pushdown automata, PDA, are a new type of computationmodel
I PDAs are like NFAs but have an extra component called astack
I The stack provides additional memory beyond the finiteamount available in the control
I The stack allows PDA to recognize some nonregular languages
Pushdown Automata
A new type of computation model
I Pushdown automata, PDA, are a new type of computationmodel
I PDAs are like NFAs but have an extra component called astack
I The stack provides additional memory beyond the finiteamount available in the control
I The stack allows PDA to recognize some nonregular languages
Pushdown Automata
A new type of computation model
I Pushdown automata, PDA, are a new type of computationmodel
I PDAs are like NFAs but have an extra component called astack
I The stack provides additional memory beyond the finiteamount available in the control
I The stack allows PDA to recognize some nonregular languages
Pushdown Automata
A new type of computation model
I Pushdown automata, PDA, are a new type of computationmodel
I PDAs are like NFAs but have an extra component called astack
I The stack provides additional memory beyond the finiteamount available in the control
I The stack allows PDA to recognize some nonregular languages
Pushdown Automata
A new type of computation model
I Pushdown automata, PDA, are a new type of computationmodel
I PDAs are like NFAs but have an extra component called astack
I The stack provides additional memory beyond the finiteamount available in the control
I The stack allows PDA to recognize some nonregular languages
Pushdown Automata
PDA and CFG
I PDA are equivalent in specification power with CFGI This is useful because it gives us two options for proving that
a language is context-free:
1. construct a CFG that generates the language or2. construct a PDA that recognizes the language
Pushdown Automata
PDA and CFG
I PDA are equivalent in specification power with CFG
I This is useful because it gives us two options for proving thata language is context-free:
1. construct a CFG that generates the language or2. construct a PDA that recognizes the language
Pushdown Automata
PDA and CFG
I PDA are equivalent in specification power with CFGI This is useful because it gives us two options for proving that
a language is context-free:
1. construct a CFG that generates the language or2. construct a PDA that recognizes the language
Pushdown Automata
PDA and CFG
I PDA are equivalent in specification power with CFGI This is useful because it gives us two options for proving that
a language is context-free:
1. construct a CFG that generates the language or
2. construct a PDA that recognizes the language
Pushdown Automata
PDA and CFG
I PDA are equivalent in specification power with CFGI This is useful because it gives us two options for proving that
a language is context-free:
1. construct a CFG that generates the language or2. construct a PDA that recognizes the language
Pushdown Automata
Note
Some CFL are more easily described in terms of their generators,whereas others are more easily described in terms of theirrecognizers
Pushdown Automata
Schematic representation of a PDA
Figure 1 contrasts the schematic representations of PDA and NFA :
Finite
Control
�rInput
a a b b
Schematic of a NFA
Finite
Control
�rInput
a a b b
-�r/wx y z . . .
Stack
Schematic of a PDA
Figure 1 : Schematic representations
Note: in Figure 1, r stands for read and w stands for write.
Pushdown Automata
More on PDA informal
I A PDA can write symbols on the stack and read them backlater
I Writing a symbol “pushes down” all the other symbols on thestack
I The symbol on the top of the stack can be read and removed.
I When the top symbol is removed the remaining symbols moveup
Pushdown Automata
More on PDA informal
I A PDA can write symbols on the stack and read them backlater
I Writing a symbol “pushes down” all the other symbols on thestack
I The symbol on the top of the stack can be read and removed.
I When the top symbol is removed the remaining symbols moveup
Pushdown Automata
More on PDA informal
I A PDA can write symbols on the stack and read them backlater
I Writing a symbol “pushes down” all the other symbols on thestack
I The symbol on the top of the stack can be read and removed.
I When the top symbol is removed the remaining symbols moveup
Pushdown Automata
More on PDA informal
I A PDA can write symbols on the stack and read them backlater
I Writing a symbol “pushes down” all the other symbols on thestack
I The symbol on the top of the stack can be read and removed.
I When the top symbol is removed the remaining symbols moveup
Pushdown Automata
More on PDA informal
I A PDA can write symbols on the stack and read them backlater
I Writing a symbol “pushes down” all the other symbols on thestack
I The symbol on the top of the stack can be read and removed.
I When the top symbol is removed the remaining symbols moveup
Pushdown Automata
Terminology
I Writing a symbol on the stack is referred to as pushing thesymbol
I Removing a symbol from the stack is referred to as poppingthe symbol
I All access to the stack may be done only at the top
In other words: a stack is a last-in first-out storage device
Pushdown Automata
Terminology
I Writing a symbol on the stack is referred to as pushing thesymbol
I Removing a symbol from the stack is referred to as poppingthe symbol
I All access to the stack may be done only at the top
In other words: a stack is a last-in first-out storage device
Pushdown Automata
Terminology
I Writing a symbol on the stack is referred to as pushing thesymbol
I Removing a symbol from the stack is referred to as poppingthe symbol
I All access to the stack may be done only at the top
In other words: a stack is a last-in first-out storage device
Pushdown Automata
Terminology
I Writing a symbol on the stack is referred to as pushing thesymbol
I Removing a symbol from the stack is referred to as poppingthe symbol
I All access to the stack may be done only at the top
In other words: a stack is a last-in first-out storage device
Pushdown Automata
Benefits of the stack
I A stack can hold an unlimited amount of information
I A PDA can recognize a language like {0n1n|n ≥ 0} because itcan use the stack to remember the number of 0s it has seen
Pushdown Automata
Benefits of the stack
I A stack can hold an unlimited amount of information
I A PDA can recognize a language like {0n1n|n ≥ 0} because itcan use the stack to remember the number of 0s it has seen
Pushdown Automata
Benefits of the stack
I A stack can hold an unlimited amount of information
I A PDA can recognize a language like {0n1n|n ≥ 0} because itcan use the stack to remember the number of 0s it has seen
Pushdown Automata
PDA recognizing {0n1n|n ≥ 0}
Informal algorithm:
1. Read symbols from the input. As each 0 is read push it onto the stack
2. As soon as a 1 is read, pop a 0 off the stack for each 1 read
3. If input finishes when stack becomes empty, accept; if stack becomes emptywhile there is still input or input finishes while stack is not empty, reject
Pushdown Automata
PDA recognizing {0n1n|n ≥ 0}
Informal algorithm:1. Read symbols from the input. As each 0 is read push it onto the stack
2. As soon as a 1 is read, pop a 0 off the stack for each 1 read
3. If input finishes when stack becomes empty, accept; if stack becomes emptywhile there is still input or input finishes while stack is not empty, reject
Pushdown Automata
PDA recognizing {0n1n|n ≥ 0}
Informal algorithm:1. Read symbols from the input. As each 0 is read push it onto the stack
2. As soon as a 1 is read, pop a 0 off the stack for each 1 read
3. If input finishes when stack becomes empty, accept; if stack becomes emptywhile there is still input or input finishes while stack is not empty, reject
Pushdown Automata
PDA recognizing {0n1n|n ≥ 0}
Informal algorithm:1. Read symbols from the input. As each 0 is read push it onto the stack
2. As soon as a 1 is read, pop a 0 off the stack for each 1 read
3. If input finishes when stack becomes empty, accept; if stack becomes emptywhile there is still input or input finishes while stack is not empty, reject
Pushdown Automata
Nature of PDA
I PDA may be nondeterministic and this is a crucial featurebecause nondeterminism adds power
I Some languages, such as {0n1n|n ≥ 0} do not requirenondeterminism, but other do. Such a language is{wwR|w ∈ {0, 1}∗}
Pushdown Automata
Nature of PDA
I PDA may be nondeterministic and this is a crucial featurebecause nondeterminism adds power
I Some languages, such as {0n1n|n ≥ 0} do not requirenondeterminism, but other do. Such a language is{wwR|w ∈ {0, 1}∗}
Pushdown Automata
Nature of PDA
I PDA may be nondeterministic and this is a crucial featurebecause nondeterminism adds power
I Some languages, such as {0n1n|n ≥ 0} do not requirenondeterminism, but other do. Such a language is{wwR|w ∈ {0, 1}∗}
Pushdown Automata
Toward PDA formalization
I Formal definition of a PDA is similar to a NFA, except the stack
I PDA my use different alphabets for input and stack, we will denote them by Σand Γ
I Nondeterminism allows PDA to make transitions on empty input. Hence we willuse Σε = Σ ∪ {ε} and Γε = Γ ∪ {ε}
I Domain of the PDA transition function is Q × Σε × Γε where Q is the set ofstates
I Since a PDA can write on the stack while performing nondeterministictransitions the range of the PDA transition function is P(Q × Γε)
In conclusion: δ : Q × Σε × Γε → P(Q × Γε)
Pushdown Automata
Toward PDA formalization
I Formal definition of a PDA is similar to a NFA, except the stack
I PDA my use different alphabets for input and stack, we will denote them by Σand Γ
I Nondeterminism allows PDA to make transitions on empty input. Hence we willuse Σε = Σ ∪ {ε} and Γε = Γ ∪ {ε}
I Domain of the PDA transition function is Q × Σε × Γε where Q is the set ofstates
I Since a PDA can write on the stack while performing nondeterministictransitions the range of the PDA transition function is P(Q × Γε)
In conclusion: δ : Q × Σε × Γε → P(Q × Γε)
Pushdown Automata
Toward PDA formalization
I Formal definition of a PDA is similar to a NFA, except the stack
I PDA my use different alphabets for input and stack, we will denote them by Σand Γ
I Nondeterminism allows PDA to make transitions on empty input. Hence we willuse Σε = Σ ∪ {ε} and Γε = Γ ∪ {ε}
I Domain of the PDA transition function is Q × Σε × Γε where Q is the set ofstates
I Since a PDA can write on the stack while performing nondeterministictransitions the range of the PDA transition function is P(Q × Γε)
In conclusion: δ : Q × Σε × Γε → P(Q × Γε)
Pushdown Automata
Toward PDA formalization
I Formal definition of a PDA is similar to a NFA, except the stack
I PDA my use different alphabets for input and stack, we will denote them by Σand Γ
I Nondeterminism allows PDA to make transitions on empty input. Hence we willuse Σε = Σ ∪ {ε} and Γε = Γ ∪ {ε}
I Domain of the PDA transition function is Q × Σε × Γε where Q is the set ofstates
I Since a PDA can write on the stack while performing nondeterministictransitions the range of the PDA transition function is P(Q × Γε)
In conclusion: δ : Q × Σε × Γε → P(Q × Γε)
Pushdown Automata
Toward PDA formalization
I Formal definition of a PDA is similar to a NFA, except the stack
I PDA my use different alphabets for input and stack, we will denote them by Σand Γ
I Nondeterminism allows PDA to make transitions on empty input. Hence we willuse Σε = Σ ∪ {ε} and Γε = Γ ∪ {ε}
I Domain of the PDA transition function is Q × Σε × Γε where Q is the set ofstates
I Since a PDA can write on the stack while performing nondeterministictransitions the range of the PDA transition function is P(Q × Γε)
In conclusion: δ : Q × Σε × Γε → P(Q × Γε)
Pushdown Automata
Toward PDA formalization
I Formal definition of a PDA is similar to a NFA, except the stack
I PDA my use different alphabets for input and stack, we will denote them by Σand Γ
I Nondeterminism allows PDA to make transitions on empty input. Hence we willuse Σε = Σ ∪ {ε} and Γε = Γ ∪ {ε}
I Domain of the PDA transition function is Q × Σε × Γε where Q is the set ofstates
I Since a PDA can write on the stack while performing nondeterministictransitions the range of the PDA transition function is P(Q × Γε)
In conclusion: δ : Q × Σε × Γε → P(Q × Γε)
Pushdown Automata
Toward PDA formalization
I Formal definition of a PDA is similar to a NFA, except the stack
I PDA my use different alphabets for input and stack, we will denote them by Σand Γ
I Nondeterminism allows PDA to make transitions on empty input. Hence we willuse Σε = Σ ∪ {ε} and Γε = Γ ∪ {ε}
I Domain of the PDA transition function is Q × Σε × Γε where Q is the set ofstates
I Since a PDA can write on the stack while performing nondeterministictransitions the range of the PDA transition function is P(Q × Γε)
In conclusion: δ : Q × Σε × Γε → P(Q × Γε)
Pushdown Automata
Definition 2.8
A pushdown automaton is a 6-tuple (Q,Σ, Γ, δ, q0,F ) where Q, Σ,Γ, and F are finite sets, and:
1. Q is a set of states
2. Σ is the input alphabet
3. Γ is the stack alphabet
4. δ : Q × Σε × Γε → P(Q × Γε) is the transition function
5. q0 ∈ Q is the start state
6. F ⊆ Q is the set of accept states
Pushdown Automata
Definition 2.8
A pushdown automaton is a 6-tuple (Q,Σ, Γ, δ, q0,F ) where Q, Σ,Γ, and F are finite sets, and:
1. Q is a set of states
2. Σ is the input alphabet
3. Γ is the stack alphabet
4. δ : Q × Σε × Γε → P(Q × Γε) is the transition function
5. q0 ∈ Q is the start state
6. F ⊆ Q is the set of accept states
Pushdown Automata
Definition 2.8
A pushdown automaton is a 6-tuple (Q,Σ, Γ, δ, q0,F ) where Q, Σ,Γ, and F are finite sets, and:
1. Q is a set of states
2. Σ is the input alphabet
3. Γ is the stack alphabet
4. δ : Q × Σε × Γε → P(Q × Γε) is the transition function
5. q0 ∈ Q is the start state
6. F ⊆ Q is the set of accept states
Pushdown Automata
Definition 2.8
A pushdown automaton is a 6-tuple (Q,Σ, Γ, δ, q0,F ) where Q, Σ,Γ, and F are finite sets, and:
1. Q is a set of states
2. Σ is the input alphabet
3. Γ is the stack alphabet
4. δ : Q × Σε × Γε → P(Q × Γε) is the transition function
5. q0 ∈ Q is the start state
6. F ⊆ Q is the set of accept states
Pushdown Automata
Definition 2.8
A pushdown automaton is a 6-tuple (Q,Σ, Γ, δ, q0,F ) where Q, Σ,Γ, and F are finite sets, and:
1. Q is a set of states
2. Σ is the input alphabet
3. Γ is the stack alphabet
4. δ : Q × Σε × Γε → P(Q × Γε) is the transition function
5. q0 ∈ Q is the start state
6. F ⊆ Q is the set of accept states
Pushdown Automata
Definition 2.8
A pushdown automaton is a 6-tuple (Q,Σ, Γ, δ, q0,F ) where Q, Σ,Γ, and F are finite sets, and:
1. Q is a set of states
2. Σ is the input alphabet
3. Γ is the stack alphabet
4. δ : Q × Σε × Γε → P(Q × Γε) is the transition function
5. q0 ∈ Q is the start state
6. F ⊆ Q is the set of accept states
Pushdown Automata
Definition 2.8
A pushdown automaton is a 6-tuple (Q,Σ, Γ, δ, q0,F ) where Q, Σ,Γ, and F are finite sets, and:
1. Q is a set of states
2. Σ is the input alphabet
3. Γ is the stack alphabet
4. δ : Q × Σε × Γε → P(Q × Γε) is the transition function
5. q0 ∈ Q is the start state
6. F ⊆ Q is the set of accept states
Pushdown Automata
PDA computation
A PDA M = (Q,Σ, Γ, δ, q0,F ) computes as follows:
I M inputs w = w1w2 . . .wm, where each wi ∈ Σε
I There are a sequence of states r0, r1, . . . , rm ∈ Q and a sequence of strings
s0, s1, . . . , sm ∈ Γ∗ that satisfy the conditions:
1. r0 = q0,s0 = ε, i.e., M starts in the start state with emptystack
2. For i = 0, 1, . . . ,m − 1 we have (ri+1, b) ∈ δ(ri ,wi+1, a) wheresi = at and si+1 = bt for some a, b ∈ Γε and t ∈ Γ∗, i.e., Mmoves properly according to the state, stack, and input symbol
3. rm ∈ F , i.e., an accept state occurs at the input end
Pushdown Automata
PDA computation
A PDA M = (Q,Σ, Γ, δ, q0,F ) computes as follows:I M inputs w = w1w2 . . .wm, where each wi ∈ Σε
I There are a sequence of states r0, r1, . . . , rm ∈ Q and a sequence of strings
s0, s1, . . . , sm ∈ Γ∗ that satisfy the conditions:
1. r0 = q0,s0 = ε, i.e., M starts in the start state with emptystack
2. For i = 0, 1, . . . ,m − 1 we have (ri+1, b) ∈ δ(ri ,wi+1, a) wheresi = at and si+1 = bt for some a, b ∈ Γε and t ∈ Γ∗, i.e., Mmoves properly according to the state, stack, and input symbol
3. rm ∈ F , i.e., an accept state occurs at the input end
Pushdown Automata
PDA computation
A PDA M = (Q,Σ, Γ, δ, q0,F ) computes as follows:I M inputs w = w1w2 . . .wm, where each wi ∈ Σε
I There are a sequence of states r0, r1, . . . , rm ∈ Q and a sequence of strings
s0, s1, . . . , sm ∈ Γ∗ that satisfy the conditions:
1. r0 = q0,s0 = ε, i.e., M starts in the start state with emptystack
2. For i = 0, 1, . . . ,m − 1 we have (ri+1, b) ∈ δ(ri ,wi+1, a) wheresi = at and si+1 = bt for some a, b ∈ Γε and t ∈ Γ∗, i.e., Mmoves properly according to the state, stack, and input symbol
3. rm ∈ F , i.e., an accept state occurs at the input end
Pushdown Automata
PDA computation
A PDA M = (Q,Σ, Γ, δ, q0,F ) computes as follows:I M inputs w = w1w2 . . .wm, where each wi ∈ Σε
I There are a sequence of states r0, r1, . . . , rm ∈ Q and a sequence of strings
s0, s1, . . . , sm ∈ Γ∗ that satisfy the conditions:
1. r0 = q0,s0 = ε, i.e., M starts in the start state with emptystack
2. For i = 0, 1, . . . ,m − 1 we have (ri+1, b) ∈ δ(ri ,wi+1, a) wheresi = at and si+1 = bt for some a, b ∈ Γε and t ∈ Γ∗, i.e., Mmoves properly according to the state, stack, and input symbol
3. rm ∈ F , i.e., an accept state occurs at the input end
Pushdown Automata
PDA computation
A PDA M = (Q,Σ, Γ, δ, q0,F ) computes as follows:I M inputs w = w1w2 . . .wm, where each wi ∈ Σε
I There are a sequence of states r0, r1, . . . , rm ∈ Q and a sequence of strings
s0, s1, . . . , sm ∈ Γ∗ that satisfy the conditions:
1. r0 = q0,s0 = ε, i.e., M starts in the start state with emptystack
2. For i = 0, 1, . . . ,m − 1 we have (ri+1, b) ∈ δ(ri ,wi+1, a) wheresi = at and si+1 = bt for some a, b ∈ Γε and t ∈ Γ∗, i.e., Mmoves properly according to the state, stack, and input symbol
3. rm ∈ F , i.e., an accept state occurs at the input end
Pushdown Automata
PDA computation
A PDA M = (Q,Σ, Γ, δ, q0,F ) computes as follows:I M inputs w = w1w2 . . .wm, where each wi ∈ Σε
I There are a sequence of states r0, r1, . . . , rm ∈ Q and a sequence of strings
s0, s1, . . . , sm ∈ Γ∗ that satisfy the conditions:
1. r0 = q0,s0 = ε, i.e., M starts in the start state with emptystack
2. For i = 0, 1, . . . ,m − 1 we have (ri+1, b) ∈ δ(ri ,wi+1, a) wheresi = at and si+1 = bt for some a, b ∈ Γε and t ∈ Γ∗, i.e., Mmoves properly according to the state, stack, and input symbol
3. rm ∈ F , i.e., an accept state occurs at the input end
Pushdown Automata
Example PDA
The PDA that recognizes the language {0n1n|n ≥ 0} isM1 = (Q,Σ, Γ, δ, q1,F ) where:
Q = {q1, q2, q3, q4}, Σ = {0, 1}, Γ = {0, $}, F = {q1, q4}δ is defined by the table:
Σε 0 1 εQ/Γε 0 $ ε 0 $ ε 0 $ εq1 {(q2, $)}q2 {(q2, 0)} {(q3, ε)}q3 {(q3, ε)} {(q4, ε)}q4
Notation: δ(q ∈ Q,w ∈ Σε, a ∈ Γε) = {(r ∈ Q, b ∈ Γε)} means qw,a→b−→ (r, b).
Pushdown Automata
Transition diagrams of PDA
I We can use state transition diagrams to describe PDA
I Such diagrams are similar to state transition diagrams used todescribe finite automata
I To show how PDA uses the stack we write “a, b → c” tosignify that the machine:
1. is reading a from input2. may replace the symbol b on top of the stack3. with the symbol c
where any of a, b, c may be ε
Pushdown Automata
Transition diagrams of PDA
I We can use state transition diagrams to describe PDA
I Such diagrams are similar to state transition diagrams used todescribe finite automata
I To show how PDA uses the stack we write “a, b → c” tosignify that the machine:
1. is reading a from input2. may replace the symbol b on top of the stack3. with the symbol c
where any of a, b, c may be ε
Pushdown Automata
Transition diagrams of PDA
I We can use state transition diagrams to describe PDA
I Such diagrams are similar to state transition diagrams used todescribe finite automata
I To show how PDA uses the stack we write “a, b → c” tosignify that the machine:
1. is reading a from input2. may replace the symbol b on top of the stack3. with the symbol c
where any of a, b, c may be ε
Pushdown Automata
Transition diagrams of PDA
I We can use state transition diagrams to describe PDA
I Such diagrams are similar to state transition diagrams used todescribe finite automata
I To show how PDA uses the stack we write “a, b → c” tosignify that the machine:
1. is reading a from input2. may replace the symbol b on top of the stack3. with the symbol c
where any of a, b, c may be ε
Pushdown Automata
Transition diagrams of PDA
I We can use state transition diagrams to describe PDA
I Such diagrams are similar to state transition diagrams used todescribe finite automata
I To show how PDA uses the stack we write “a, b → c” tosignify that the machine:
1. is reading a from input
2. may replace the symbol b on top of the stack3. with the symbol c
where any of a, b, c may be ε
Pushdown Automata
Transition diagrams of PDA
I We can use state transition diagrams to describe PDA
I Such diagrams are similar to state transition diagrams used todescribe finite automata
I To show how PDA uses the stack we write “a, b → c” tosignify that the machine:
1. is reading a from input2. may replace the symbol b on top of the stack
3. with the symbol c
where any of a, b, c may be ε
Pushdown Automata
Transition diagrams of PDA
I We can use state transition diagrams to describe PDA
I Such diagrams are similar to state transition diagrams used todescribe finite automata
I To show how PDA uses the stack we write “a, b → c” tosignify that the machine:
1. is reading a from input2. may replace the symbol b on top of the stack3. with the symbol c
where any of a, b, c may be ε
Pushdown Automata
Transition diagrams of PDA
I We can use state transition diagrams to describe PDA
I Such diagrams are similar to state transition diagrams used todescribe finite automata
I To show how PDA uses the stack we write “a, b → c” tosignify that the machine:
1. is reading a from input2. may replace the symbol b on top of the stack3. with the symbol c
where any of a, b, c may be ε
Pushdown Automata
Interpretation
I If a is ε, the machine makes this transaction without readingany symbol from the input
I If b is ε, the machine makes this transaction without poppingany symbol from the stack
I If c is ε, the machine makes this transaction without pushingany symbol on the stack
Pushdown Automata
Transition diagram of PDA M1
Figure 2 show the state transition diagram of M1 recognizing thelanguage {0n1n|n ≥ 0}
-��������q1 -ε, ε→ $����
q2
9
0, ε→ 0
?1, 0→ ε
��������q4 �
ε, $→ ε����
q3
9
1, 0→ ε
Figure 2 : Transition diagram for PDA M1
Pushdown Automata
Note 1
I The formal definition of a PDA contains no explicitmechanism for testing the empty stack
I PDA in Figure 2 test empty stack by initially placing a specialsymbol, $, on the stack
I If ever it sees $ again on the stack, it knows that the stack iseffectively empty
This is the procedure we use to test empty stack
Pushdown Automata
Note 2
I The PDA has no mechanism to test explicitly the reaching ofend of the input
I The PDA in Figure 2 is able to achieve this effect because theaccept state takes effect only when the machine is at the endof the output
Thus, from now on we assume that PDA can test for end of input,and we know that we can implement it in the same manner
Pushdown Automata
Example 2.10
This example provides the PDA M2 that recognizes the language{aibjck |i , j , k ≥ 0 and i = j or i = k}
Informal description:
I The PDA first reads and push a’s on the stack
I When this is done, it can match as with bs or cs
I Since machine does not know in advance whether as are matched with bs or cs,nondeterminism helps
I Using nondeterminism the machine can guess: the machine has two branches,one for each possible guess
I If either of these branches match, that branch accepts and the entire machineaccepts
Pushdown Automata
Example 2.10
This example provides the PDA M2 that recognizes the language{aibjck |i , j , k ≥ 0 and i = j or i = k}
Informal description:I The PDA first reads and push a’s on the stack
I When this is done, it can match as with bs or cs
I Since machine does not know in advance whether as are matched with bs or cs,nondeterminism helps
I Using nondeterminism the machine can guess: the machine has two branches,one for each possible guess
I If either of these branches match, that branch accepts and the entire machineaccepts
Pushdown Automata
Example 2.10
This example provides the PDA M2 that recognizes the language{aibjck |i , j , k ≥ 0 and i = j or i = k}
Informal description:I The PDA first reads and push a’s on the stack
I When this is done, it can match as with bs or cs
I Since machine does not know in advance whether as are matched with bs or cs,nondeterminism helps
I Using nondeterminism the machine can guess: the machine has two branches,one for each possible guess
I If either of these branches match, that branch accepts and the entire machineaccepts
Pushdown Automata
Example 2.10
This example provides the PDA M2 that recognizes the language{aibjck |i , j , k ≥ 0 and i = j or i = k}
Informal description:I The PDA first reads and push a’s on the stack
I When this is done, it can match as with bs or cs
I Since machine does not know in advance whether as are matched with bs or cs,nondeterminism helps
I Using nondeterminism the machine can guess: the machine has two branches,one for each possible guess
I If either of these branches match, that branch accepts and the entire machineaccepts
Pushdown Automata
Example 2.10
This example provides the PDA M2 that recognizes the language{aibjck |i , j , k ≥ 0 and i = j or i = k}
Informal description:I The PDA first reads and push a’s on the stack
I When this is done, it can match as with bs or cs
I Since machine does not know in advance whether as are matched with bs or cs,nondeterminism helps
I Using nondeterminism the machine can guess: the machine has two branches,one for each possible guess
I If either of these branches match, that branch accepts and the entire machineaccepts
Pushdown Automata
Example 2.10
This example provides the PDA M2 that recognizes the language{aibjck |i , j , k ≥ 0 and i = j or i = k}
Informal description:I The PDA first reads and push a’s on the stack
I When this is done, it can match as with bs or cs
I Since machine does not know in advance whether as are matched with bs or cs,nondeterminism helps
I Using nondeterminism the machine can guess: the machine has two branches,one for each possible guess
I If either of these branches match, that branch accepts and the entire machineaccepts
Pushdown Automata
M2 recognizing {aibjck |i , j , k ≥ 0 ∧ i = j ∨ i = k}
The transition diagram is in Figure 3
- jq1 -ε, ε→ $ jq2
6a, ε→ a
-ε, ε→ ε jq5
6b, ε→ ε
-ε, ε→ ε jq6
6c, a→ ε
-ε, $→ ε jhq7
����3
ε, ε→ ε
jq3
?
b, a→ ε
-ε, $→ ε jhq4
?
c, ε→ ε
Figure 3 : Transition diagram of PDA M2
Pushdown Automata
Example 2.11
This example provides the PDA M3 that recognizes the language{wwR|w ∈ {0, 1}∗}.
Recall: wR means w written backwards.
Pushdown Automata
Informal description
1. M3 begins by pushing the symbols that are read onto the stack
2. At each point M3 nondeterministically guesses that the middle of the input hasbeen reached
3. When middle of the word has reached the machine starts popping off the stackfor each symbol read, checking to see that what is read and what is popped offis the same symbol
4. If the symbol read from the input and popped out from the stack is the sameand the stack empties as the same time as input is finished, accept; otherwisereject
Pushdown Automata
Informal description
1. M3 begins by pushing the symbols that are read onto the stack
2. At each point M3 nondeterministically guesses that the middle of the input hasbeen reached
3. When middle of the word has reached the machine starts popping off the stackfor each symbol read, checking to see that what is read and what is popped offis the same symbol
4. If the symbol read from the input and popped out from the stack is the sameand the stack empties as the same time as input is finished, accept; otherwisereject
Pushdown Automata
Informal description
1. M3 begins by pushing the symbols that are read onto the stack
2. At each point M3 nondeterministically guesses that the middle of the input hasbeen reached
3. When middle of the word has reached the machine starts popping off the stackfor each symbol read, checking to see that what is read and what is popped offis the same symbol
4. If the symbol read from the input and popped out from the stack is the sameand the stack empties as the same time as input is finished, accept; otherwisereject
Pushdown Automata
Informal description
1. M3 begins by pushing the symbols that are read onto the stack
2. At each point M3 nondeterministically guesses that the middle of the input hasbeen reached
3. When middle of the word has reached the machine starts popping off the stackfor each symbol read, checking to see that what is read and what is popped offis the same symbol
4. If the symbol read from the input and popped out from the stack is the sameand the stack empties as the same time as input is finished, accept; otherwisereject
Pushdown Automata
Informal description
1. M3 begins by pushing the symbols that are read onto the stack
2. At each point M3 nondeterministically guesses that the middle of the input hasbeen reached
3. When middle of the word has reached the machine starts popping off the stackfor each symbol read, checking to see that what is read and what is popped offis the same symbol
4. If the symbol read from the input and popped out from the stack is the sameand the stack empties as the same time as input is finished, accept; otherwisereject
Pushdown Automata
Transition diagram of PDA M3
Figure 4 shows the state transition diagram of M4 recognizing thelanguage {wwR|w ∈ {0, 1}}
-��������q1 -ε, ε→ $����
q2
90, ε→ 0
1, ε→ 1
?ε, ε→ ε
��������q4 �
ε, $→ ε����
q3
90, 0→ ε
1, 1→ ε
Figure 4 : Transition diagram for PDA M3
Pushdown Automata