Finite Automata
Finite Automata
Languages
language (over an alphabet ) is any subset of the set of all possible strings over . The set of all possible strings is written as *. Example:
A
= {a, b, c} * = {, a, b, c, ab, ac, ba, bc, ca, aaa, } one language might be the set of strings of length less than or equal to 2.
L = {, a, b, c, aa, ab, ac, ba, bb, bc, ca, cb, cc}
Finite Automata
A
deterministic finite automaton (dfa) is a mathematical model for a machine that can accept certain types of languages. The singular is automaton, the plural is automata.
Finite Automata
on/off switch
input tape
A finite automaton
Finite Automata
The
machine, or automaton, when on, will at any moment be in some "state". This type of machine has only a finite number of states. The machine goes into new states as it reads the input tape. When the light is on, the string up to that point is "accepted". When off, it is "rejected". The machine has to read all the way to the last character on the tape.
Finite Automata
A
The
transition function specifies, for each state and symbol, the next state the machine will enter.
Finite Automata
The
transition function specifies, for each state and symbol, the next state the machine will enter. When we write (q1, b) = q2, we are saying that if the machine is in state q1 and the next symbol read is b, then the state of the machine becomes state q2. The machine always starts in the initial state looking at the leftmost symbol on the tape. The machine stops after reading the rightmost symbol on the tape.
Finite Automata
transitive closure of , written as *(q1, w) = q2 is used to represent the fact that the machine, when in state q1, winds up in state q2 by following the path that exists for the transitions specified by the series of symbols in w. For example, if (q1, a) = q2, (q2, b) = q3 and (q3, a) = q4, then *(q1, aba) = q4.
The
Finite Automata
The
language accepted by a dfa is exactly the set of strings over the alphabet that result in the machine ending in an accepting state. The language is symbolized as L(M). The transition function makes the automaton deterministic. At each moment in time, the machine has exact instructions as to what will happen next.
Bubble Diagrams
In order to visualize a particular finite automaton, we draw a bubble diagram, (or bubble chart). Here's a simple example:
b a
The circles represent states, with a double circle being an accepting state. The arcs represent the transitions of the transition function.
Bubble Diagrams
What
b
a
L
Example 1
a
q3
a, b
q2
a, b
What is (q1, b)? q1 q3 What is *(q0. abbaba)? Given that q3 is the only accepting state, what is L(M), the language is accepted by this machine?
Example 2
Construct a
dfa that accepts the language L = {x {a, b} | x begins and ends with the sequence aab.} b a a a b a a
A AA AAB A AA
b a
x
accepting state.
b
b a,b "trap" state
Why?
Example 2
Construct a
dfa that accepts the language L = {x {a, b} | x begins and ends with the sequence aab.} b a a a b a a
q0 q1 q2 q3 q4 q5
b
qT
b a
q6
b
b a,b
Example 2
a q0 q1 q2 q3 q1 q2 qT q4 b qT qT q3 q6
Table format
q4
q5 q6 qT
q5
q5 q4 qT
q6
q3 q6 qT
Example 3
Construct a
dfa that accepts the language L = {x {a, b} | x has an even number of a's and an odd number of b's.}
EE
a a
OE
b
EO
b a a
b
OO
Example 4
Construct a
dfa that accepts the language L = {x {a, b} | x consists of even number of a's followed by an odd number of b's.} a b a a
a
b
a,b
b
b
Finite Automata
That's
how finite automata are built, and that's how they work. Some automata are easy to construct; others quite tricky or difficult. Representations:
table format
good for computer simulation good for applying certain algorithms
how annoying all the necessary detail is. Perhaps we can come up with a more powerful and more convenient automaton.
non-deterministic finite automaton (nfa) is a quintuple M = (Q, , , q0, F) , where Q is a finite set of states, is a finite set of symbols (the alphabet), q0 is one of the states in Q (called the initial state), F is a subset of Q and represents the final, or accepting states of M, and : Q {, } 2Q is the transition function of M.
only difference is in the transition function. We now allow the machine to go to a new state WITHOUT looking at a symbol. ( transitions) We also allow the machine the choice of going to any of a number of states for a given symbol!!! (non-deterministic transitions)
have just made this machine smart, as we will shortly see. Having non-deterministic transitions means that we can specify no transition for a qiven state and symbol as well, which makes design a little less cluttered because we don't have worry about "useless" stuff.
But
if there is ANY path from the initial state to an accepting state for a given string
that string is accepted and belongs to L(M). even if only one out of a million paths leads to an accepting state!!!!
Now
thats smart!
Constructing an nfa
Construct an
nfa that accepts the language L = {x {a, b} | x begins and ends with the sequence aab.} a a b end of
q0 q1 q2 q3
string: aab
q6 q7
We
"prove" this by demonstrating an algorithm that converts any nfa into a corresponding dfa. The book describes the algorithm, but it's hard to understand; we'll look at how it works by studying the last example.
a q0 q1 q2 {q1} {q2}
b {q3}
*(q0, a) = {q1} so (Q0, a) in the corresponding dfa would equal Q1. The subscript of Q represents the set of states that the nfa could wind up in. *(q0, b) = {} so (Q0, b) in the corresponding dfa would equal QT, the trap state.
q3 q4 q5 q6 q7
{q4} {q7}
{q4}
Of course (QT, a) = (QT, b) = QT since it's the trap state. Now we proceed to state Q1 and draw arcs for a and for b. We keep going until we add no more new states to the dfa and all the transitions have been specified. Note that since (q3, a) = {q4, q5}, (Q3, a) = Q45
a q0 q1 q2 {q1} {q2}
b {q3}
q3 q4 q5 q6 q7
{q4} {q7}
{q4}
a
Q0 Q1
a
Q2
b
Q3
q0
{q1}
b
QT
a b a
Q45
q1
q2 q3 q4
{q2}
{q4, q5}
a
Q456
b
b
Q4
a b
Q47
q5
q6 q7
{q6}
{q7}
a, b
a because of the transition, if the nfa is in q3, it could just as well be in q4. (the closure of q3 is {q3, q4}
Start with the initial state of the nfa Create a corresponding initial state in the dfa For each symbol of the alphabet, find the set of states that you could wind up in. Create a corresponding state in the dfa. Keep going until there are no more states, and no more transitions need to be drawn.
Note: When there are lambda transitions, you have to look at the closure. Remember: a = a = a
Any state in the dfa which has in it the number of an accepting state of the nfa becomes an accepting state.
12
2.2/2-12
2.3/1-6, 8,
12