Finite Automata: A Simple Computing Model
Finite Automata: A Simple Computing Model
1
Outline (this and next lecture)
Introduction
Deterministic finite automata (DFA’s)
Non-deterministic finite automata (NFA’s)
NFA’s to DFA’s
Simplifying DFA’s
Regular expressions finite automata
Open Closed
A, no B
No A or B
A and B A and B
A, no B B, no A
B, no A No A or B
4
This is a finite automaton!
8
More formally…
9
EXAMPLE: (a+b)*
Construct a DFA to recognize the regular
languages represented by the regular
expression (a + b)* over alphabet A = {a, b}.
This is the set {a, b}* of all strings over {a, b}.
This can be recognised by
10
EXAMPLE: a(a+b)*
11
EXAMPLE: Pattern recognition
Build a DFA to recognize the regular language
represented by the regular expression
(a + b)*abb over the alphabet A = {a, b}.
is represented by:
T(i,a) = j
Kleene (1956)
20
EXAMPLE
22
NFA transition functions
Since there may be nondeterminism, we'll let
the values of this function be sets of states.
For example, if there are no edges from state k
labelled with a, we'll write
T(k, a) = .
23
Comments on non-determinism
All digital computers are deterministic; quantum
computers may be another story!
The usual mechanism for deterministic
computers is to try one particular path and to
backtrack to the last decision point if that
path proves poor
Parallel computers make non-determinism
almost realizable. We can let each process
make a random choice at each branch point,
thereby exploring many possible trees.
24
Perhaps surprisingly:
A A,B A,C
a b
DFA
b a a
b
28
Summary…
29
Finite automata
So far, we’ve introduced two kinds of automata:
deterministic and non-deterministic.
We’ve shown that we can find a DFA to recognise
anything language that a given NFA recognises.
Start the algorithm with a machine that has a start state, a single
final state, and an edge labelled with the given regular expression
as follows:
31
Four step algorithm
1. If an edge is labelled with , then erase the
edge.
2. Transform any diagram like
32
3. Transform any diagram like
33
4. Transform any diagram like
34
Example – a* + ab
a* + ab
Apply rule 2
a*
ab
35
Example – a* + ab
a
Apply rule 4
to a*
ab
a
Apply rule 3
to ab
a b
36
Finite Automaton Regular Expression
37
3. For each pair of states i and j that have more
than one edge from i to j, replace all the
edges from i to j by a single edge labelled with
the regular expression formed by the sum of
the labels on each of the edges from i to j.
38
Eliminating states
As each state is eliminated, a new machine is
constructed from the previous machine as
follows:
Let old(i,j) denote the label on edge i,j of the
current machine. If no edge exists, label it .
Assume that we wish to eliminate state k. For
each pair of edges i,k (incoming edge) and
k,j (outgoing edge) we create a new edge
label new(i, j)
39
Eliminate state k
The label of this new edge is given by:
new(i,j) = old(i,j) + old(i, k) old(k, k)*
old(k,j)
All other edges, not involving state k, remain the
same:
new(i, j) = old(i, j).
Initial DFA
Steps 1 and 2
Add start and
final states
41
Eliminate state 2
(No path to f)
Eliminate state 0
Eliminate state 1
Myhill-Nerode theorem:
‘Every regular expression has a unique*
minimum state DFA’
* up to a simple renaming of the states
43
Finding minimum state DFA
44
Consider the DFA b
1 a a,b
a
b a
2
b
46
Part 2: construct minimum DFA
1. Construct a new DFA where any pairs of
indistinguishable states form a single state
in the new DFA
2. The start state will be the state containing
the original start state.
3. The final states will be those which contain
original final states
4. The transitions will be the full set of
transitions from the original states (these
should all be consistent.)
47
Example
1 a
b
b b a,b
a
0 2 4
b
a a
3
Finally, as before,
T(4, a) = 4 and T(4, b) = 4
51
Resulting minimal DFA
0 1, 2, 3 4