417 lecture note #6
[J: 10.1,2,4] Automata, Grammars and Languages (1)
0. Intro to Finite State Automata
- A finite state automaton (FSA) is an abstract
model of a computing machine with a primitive memory.
- An FSA can only model rather easy computations. But it is
very useful: there are many things/machines in our
every-day life that perform this kind of computations.
This means our world is not so complex (?!)
- An FSA is basically a directed graph
with labeled edges, and each vertex represents a state
in the computation. Then the computation is performed by
making transitions between states
according to the input.
- Example (1): A 30 cent newspaper vending machine

- Example (2): Regular expressions in unix shell or
Perl language (used for pattern matching)
1. Finite State Machine
- The machine which is the core of an FSA.
- As the computation makes state transitions, the machine
produces some output.
- Definition: A finite state machine M = (I,
O, S, f, g, s), where
- I -- set of possible input symbols
- O --set of possible output symbols
- S --set of states
- f --a next-state function from S
* I into S
- g --an output function from S
* I into O
- s -- the initial
state (s Î S)
- Input & Output for an FSM
- Input -- a string consisting of symbols in I
- Output -- a string consisting of symbols in O
- Example (10.1.5, 10.5.6):
- A machine M = (I, O, S,
f, g, s), where
- I = {a,b}
- O = {0,1}
- S = {s0, s1}
- s = s0
- f, g -- given by a transition
diagram or a transition table

| f(s0,
a) = s0
|
g(s0,
a) = 0 |
| f(s0,
b) = s1
|
g(s0,
b) = 1 |
| f(s1,
a) = s1
|
g(s1,
a) = 1 |
| f(s1,
b) = s1
|
g(s1,
b) = 0 |
- Sample Input/Output:
- Input = aababba; Output = 0011001
- Input = aaa; Output = 000
- Examples:
- Exercise 21: An FSM which outputs 1 if an even
number of 1's have been input; otherwise outputs
0.
2. Finite State Automata
- A finite state automaton is a special kind of FSM, where
- Output symbols are {0, 1}.
- States to which a transition with output 1 exists
are called accepting states
(usually marked with double circles).
- For the reason above, output symbols in
transition diagram/table are often omitted.
- Any input to an FSA which lands in one of the accepting
states at the end of transitions is accepted by the
machine. Thus, the FSA is used to recognize
input strings.
- Definition: A finite state automaton A = (I,
S, f, A, s), where
- I -- set of possible input symbols
- S --set of states
- f --a next-state function from S
x I into S
- A -- set of accepting states (A Í S)
- s -- the
initial state (s Î S)
- A null string is accepted only if the
start state is also an accepting state.
- IMPORTANT NOTE:
- For each state, transitions for ALL input
symbols must be defined.
- Example (10.2.2):
- I = {a, b}
- S = {s0,
s1,
s2}
- A = {s1,
s2}
- s = s0
- f = given by the following transition
diagram

| Input string |
Accept/Reject? |
| abbaa |
|
| bbabb |
|
| ababaaa |
|
3. Nondeterministic Finite State Automata (NDFSA's)
- A nondeterministic finite state automata (NDFSA) is a
special kind of FSA (or deterministic FSA -- DFSA), where
- next-state function f is not
defined for all S * I (i.e.,
some missing transitions); and/or
- next-state function f has multiple
transitions for a given [state, symbol]
pair (f: S * I -> P(S), a powerset
of S)
- Example (10.4.6):

- Strings accepted by NDFSA's
- A string is accepted by a
nondeterministic finite state automata A = (I,
S, f, A, s) if there is any
path (i.e., at least
one path )from the start state to an
accepting state. Let a = [x1,..,xn] be a
nonnull string. a is accepted
by A if there exists a sequence of states [s0,..,sn] such that
- s0 = s
- si Î f(si-1, xi) for all i, 1
<= i <= n
- sn Î A
- A null string is accepted only if s0 Î A.
- IMPORTANT NOTES:
- A string is accepted only if ALL input
symbols are processed AND the last state is one of the
accepting states at the same time.
- So, a string is rejected if
- the processing gets stuck because there is no transition
specified for the current input symbol, no matter what state
(accepting/non-accepting) the processing stops at; or
- the processing succeeded till the end of an input string, and
the last state is a non-accepting state.
- More Examples of non-deterministic FSA's
- Accept strings that start with ab
- I = {a,b}
- Transition diagram:
- Accept strings that contain ab
- I = {a,b}
- Transition diagram:
- (Section 10.5, Exercise #27)
Accept strings that start with ab but do not end with ab.
- I = {a,b}
- Transition diagram:
4. Constructing an equivalent DFSA from an NDFSA
- States in DFSA correspond to the power set of states in
the NDFSA
- Two methods: (1) All powersets and (2) Subset
construction
(1) All powersets (the way explained in
Johnsonbaugh's) -- easier way
- From a NDFSA N = (I, S, f, A,
s), construct a DFSA
D = (I', S', f', A', s')
where
- I' = I
- S' = P(S), all powersets of S
- f' = a
next-state function from S' x I'
into S' , derived from f
- A' =
set of accepting states (A' Í S')
- s'
= {s}, a
singleton set of the start state s
- How to derive f'
from f
- A' -- the
accepting states in the DFSA
- Mark all states in the DFSA whose
labels contain at least one accepting state in
the NDFSA.
- New DFSA

- Then, simplify the transition diagram by
eliminating nodes which are unreachable
from the start state.

(2) Subset construction
- Start from {s}, a
singleton set of the start state s
- Do forward propagation and create states and add
transitions
- Steps to construct transition diagram:
- For any given state whose label is {x1,..,xn} in an
already constructed S in the DFSA, consider
all transitions defined in the NDFSA from all
states x1,..,xn
for each possible input character c.
Make a set of all destination states {y1,..,yn} from
x1,..,xn,
and add a new transition f({x1,..,xn}, c) = {y1,..,yn} in the
DFSA.
- Repeat the procedure above until
all transitions in NDFSA are represented in the
DFSA.
- Check each state in the resulting
DFSA to see whether transitions are defined for
the state for all possible input symbols. If
there is any missing symbol, create a dead state
(with a label Æ) and add a transition to that state.
- Mark accepting states -- all nodes
whose label contains at least one accepting state
in the NDFSA.
- No state elimination step is needed.
- Resulting transition diagram -- same as the one created
by the all powersets method.