0% found this document useful (0 votes)
154 views23 pages

PDA-7 Tuple Machine

This document describes pushdown automata (PDA), which are finite automata augmented with a stack to provide unbounded memory. A PDA uses its finite state control along with transitions based on the current input symbol and top of the stack, which can optionally pop or push symbols. This allows PDAs to recognize context-free languages by using the stack for tasks like counting. The document provides examples of simple PDAs for balanced parentheses and palindromes to illustrate how they work.

Uploaded by

Sinan Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
154 views23 pages

PDA-7 Tuple Machine

This document describes pushdown automata (PDA), which are finite automata augmented with a stack to provide unbounded memory. A PDA uses its finite state control along with transitions based on the current input symbol and top of the stack, which can optionally pop or push symbols. This allows PDAs to recognize context-free languages by using the stack for tasks like counting. The document provides examples of simple PDAs for balanced parentheses and palindromes to illustrate how they work.

Uploaded by

Sinan Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Pushdown Automata

The Problem
● Finite automata accept precisely the regular
languages.
● We may need unbounded memory to recognize
context-free languages.
● e.g. { 0n1n| n ∈ ℕ } requires unbounded counting.
How do we build an automaton with finitely

many states but unbounded memory?
The finite-state
control acts as a
finite memory.

The input tape holds the


input string.

A B C A ...

Memory Device We can add an infinite


memory device the finite-state
control can use to store
information.
Adding Memory to Automata
● We can augment a finite automaton by adding
in a memory device for the automaton to store
extra information.
● The finite automaton now can base its transition on
both the current symbol being read and values stored
in memory.
● The finite automaton can issue commands to the
memory device whenever it makes a transition.

● e.g. add new data, change existing data, etc.


Stack-Based Memory
● Only the top of the stack is visible at any point in
time.
● New symbols may be pushed onto the
stack, which cover up the old stack top.
● The top symbol of the stack may be
popped, exposing the symbol below it.
Pushdown Automata

A pushdown automaton (PDA) is a finite automaton
equipped with a stack-based memory.
● Each transition
● is based on the current input symbol and the top of the stack,
optionally pops the top of the stack, and optionally pushes

new symbols onto the stack.

● Initially, the stack holds a special symbol Z0 that indicates


the bottom of the stack.
Our First PDA
● Consider the language
L = { w ∈ Σ* | w is a string of balanced
digits }
over Σ = { 0, 1 }
● We can exploit the stack to our advantage:
● Whenever we see a 0, push it onto the stack. Whenever
● we see a 1, pop the corresponding 0
from the stack (or fail if not matched)
● When input is consumed, if the stack is empty, accept.
A Simple Pushdown Automaton
To find an applicable
0, Z0 → 0Z0 transition, match the
0, 0 → 00 current input/stack pair.
1, 0 → ε
ε, Z0 → ε
start

A transition of the form

a, b → z
Z0
Means “If the current input symbol
is a and the current stack symbol is b,
then follow this transition, pop b, and
push the string z. 0 0 0 1 1 1
A Simple Pushdown Automaton
0, Z0 → 0Z0
0, 0 → 00
1, 0 → ε
ε, Z0 → ε
start

If a transition reads the top symbol of


the stack, it always
pops that symbol (though it might
replace it)

0 0 0 1 1 1
A Simple Pushdown Automaton
0, Z0 → 0Z0
0, 0 → 00
1, 0 → ε
ε, Z0 → ε
start

Each transition then pushes some


(possibly empty) string back onto the 0 Z0
stack. Notice that the leftmost symbol
is pushed onto the top.

0 0 0 1 1 1
A Simple Pushdown Automaton
0, Z0 → 0Z0
0, 0 → 00
1, 0 → ε
ε, Z0 → ε
start

We now push the string ε onto


the stack, which adds no new
characters. This essentially
0 0 Z0
means “pop the stack.”

0 0 0 1 1 1
A Simple Pushdown Automaton
0, Z0 → 0Z0
0, 0 → 00
1, 0 → ε
ε, Z0 → ε
start

This transition can be taken at any


time Z0 is atop the stack, but we've Z0
nondeterministically guessed that this
would be a good time to take it.

0 0 0 1 1 1
A Simple Pushdown Automaton
0, Z0 → 0Z0
0, 0 → 00
1, 0 → ε
ε, Z0 → ε
start

0 0 0 1 1 1
Pushdown Automata
● Formally, a pushdown automaton is a nondeterministic machine
defined by the 7-tuple (Q, Σ, Γ, δ, q0, Z0, F), where

● Q is a finite set of states, Σ is


● an alphabet,
● Γ is the stack alphabet of symbols that can be pushed on the stack,
δ : Q × Σε × Γε → ℘(Q × Γ*) is the transition function, where no tuple
● is mapped to an infinite set,
q0 ∈ Q is the start state,

Z0 ∈ Γ is the stack start symbol, and F ⊆ Q is

the set of accepting states.

● The automaton accepts if it ends in an accepting state with no


input remaining.
The Language of a PDA
● The language of a PDA is the set of strings
that the PDA accepts:
ℒ(P) = { w ∈ Σ* | P accepts w }
● If P is a PDA where ℒ(P) = L, we say that
P recognizes L.
Pushdown Automata
● Formally, a pushdown automaton is a nondeterministic machine
defined by the 6-tuple (Q, Σ, Γ, δ, q0, F), where

● Q is a finite set of states, Σ is


● an alphabet,
● Γ is the stack alphabet of symbols that can be pushed on the stack,
δ : Q × Σε × Γε → ℘(Q × Γ*) is the transition function, where no tuple
● is mapped to an infinite set,
q0 ∈ Q is the start state,

the set of accepting states.

● The automaton accepts if it ends in an accepting state with no


input remaining.
A Note on Terminology
● Finite automata are highly standardized.

There are many equivalent but different
definitions of PDAs.

The one we will use is a slight variant on the one described
in Sipser.
● Sipser does not have a start stack symbol.
● Sipser does not allow transitions to push multiple symbols
onto the stack.

Feel free to use either this version or Sipser's; the two are
equivalent to one another.
A PDA for Palindromes
● A palindrome is a string that is the same forwards and
backwards.
● Let Σ = {0, 1} and consider the language
PALINDROME = { w ∈ Σ* | w is a palindrome }.
● How would we build a PDA for PALINDROME?

Idea: Push the first half of the symbols on to the stack, then verify
that the second half of the symbols match.

Nondeterministically guess when we've read half of the symbols.
This handles even-length strings; we'll see a cute trick to handle

odd-length strings in a minute.
A PDA for Palindromes

This transition indicates that the


0, ε → 0 transition does notpop anything
1, ε → 1 from the stack. It just pushes on
a new symbol instead.
start
A PDA for Palindromes

The Σ here refers to the same


symbol inboth
Σ, ε → Σ contexts. It is a
shorthand for “treat any
start symbol in Σ this way”
A PDA for Palindromes

Σ, ε → Σ

ε, ε → ε
start

This transition means “don't consume any input, don't change the
top of the stack, and don't
add anything to a stack. It's the equivalent of an ε-transition in
an NFA.
A PDA for Palindromes

Σ, ε → Σ Σ, Σ → ε
ε, ε → ε
Σ, ε → ε ε, Z0 → ε
start

This transition lets us consume one


character before we start
matching what we just saw. This
lets us match odd-length
palindromes
A Note on Nondeterminism
● In a PDA, if there are multiple nondeterministic
choices, you cannot treat the machine as being in
multiple states at once.

● Each state might have its own stack


associated with it.
● Instead, there are multiple parallel copies of the
machine running at once, each of which has its
own stack.

You might also like