Documente Academic
Documente Profesional
Documente Cultură
Chapter 2
Finite Automata
H. Conrad Cunningham
29 December 2015
Contents
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.1 Deterministic Finite Accepters . . . . . . . . . . . . . . . . . . . 2
2.1.1 Accepters . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.1.2 Transition Graphs . . . . . . . . . . . . . . . . . . . . . . 3
2.1.3 Linz Example 2.1 . . . . . . . . . . . . . . . . . . . . . . . 3
2.1.4 Extended Transition Function for a DFA . . . . . . . . . 4
2.1.5 Language Accepted by a DFA . . . . . . . . . . . . . . . . 4
2.1.6 Linz Example 2.2 . . . . . . . . . . . . . . . . . . . . . . . 4
2.1.7 Linz Example 2.3 . . . . . . . . . . . . . . . . . . . . . . . 5
2.1.8 Linz Example 2.4 . . . . . . . . . . . . . . . . . . . . . . . 5
2.1.9 Regular Languages . . . . . . . . . . . . . . . . . . . . . . 7
2.1.10 Linz Example 2.5 . . . . . . . . . . . . . . . . . . . . . . . 7
2.1.11 Linz Example 2.6 . . . . . . . . . . . . . . . . . . . . . . . 8
2.2 Nondeterministic Finite Accepters . . . . . . . . . . . . . . . . . 8
2.2.1 Nondeterministic Accepters . . . . . . . . . . . . . . . . . 8
2.2.2 Linz Example 2.7 . . . . . . . . . . . . . . . . . . . . . . . 9
2.2.3 Linz Example 2.8 . . . . . . . . . . . . . . . . . . . . . . . 9
2.2.4 Extended Transition Function for an NFA . . . . . . . . . 11
1
2.2.5 Language Accepted by an NFA . . . . . . . . . . . . . . . 11
2.2.6 Linz Example 2.10 (Example 2.8 Revisited) . . . . . . . . 11
2.2.7 Why Nondeterminism . . . . . . . . . . . . . . . . . . . . 12
2.3 Equivalence of DFAs and NFAs . . . . . . . . . . . . . . . . . . . 12
2.3.1 Meaning of Equivalence . . . . . . . . . . . . . . . . . . . 12
2.3.2 Linz Example 2.11 . . . . . . . . . . . . . . . . . . . . . . 13
2.3.3 Power of NFA versus DFA . . . . . . . . . . . . . . . . . . 13
2.3.4 Linz Example 2.12 . . . . . . . . . . . . . . . . . . . . . . 15
2.3.5 Linz Example 2.13 . . . . . . . . . . . . . . . . . . . . . . 18
2.4 Reduction in the Number of States in Finite Automata . . . . . . 19
Copyright (C) 2015, H. Conrad Cunningham
Acknowledgements: These lecture notes are for use with Chapter 2 of the
textbook: Peter Linz. Introduction to Formal Languages and Automata, Fifth
Edition, Jones and Bartlett Learning, 2012. The terminology and notation used
in these notes are similar to those used in the Linz textbook. This document
uses several figures from the Linz textbook.
Advisory: The HTML version of this document requires use of a browser that
supports the display of MathML. A good choice as of December 2015 seems to
be a recent version of Firefox from Mozilla.
Introduction
2.1.1 Accepters
2
• δ : Q × Σ → Q is a total function called the transition function
• q0 ∈ Q is the initial state.
• F ⊆ Q is a set of final states.
The graph pictured in Linz Figure 2.1 represents the dfa M = ({q0 , q1 , q2 }, {0, 1}, δ, q0 , {q1 }),
where δ is represented by
δ(q0 , 0) = q0 , δ(q0 , 1) = q1
δ(q1 , 0) = q0 , δ(q1 , 1) = q2
δ(q2 , 0) = q2 , δ(q2 , 1) = q1
Note that q0 is the initial state and q1 is the only final state in this dfa.
The dfa in Linz Figure 2.1:
3
Linz Fig. 2.1: DFA Transition Graph
δ ∗ (q, λ) = q
δ ∗ (q, wa) = δ(δ ∗ (q, w), a)
The extended transition function gives the state of the automaton after reading
a string.
The automaton in Linz Figure 2.2 accepts all strings consisting of arbitrary
numbers of a’s followed by a single b.
In set notation, the language accepted by the automaton is L = {an b : n ≥ 0}.
Note that q2 has two self-loop edges, each with a different label. We write this
compactly with multiple labels.
A trap state is a state from which the automaton can never “escape”.
Note that q2 is a trap state in the dfa transition graph shown in Linz Figure 2.2.
Transition graphs are quite convenient for understanding finite automata.
4
Linz Fig. 2.2: DFA Transition Graph with Trap State
Find a deterministic finite accepter that recognizes the set of all string on
Σ = {a, b} starting with the prefix ab.
Linz Figure 2.4 shows a transition graph for a dfa for this example.
The dfa must accept ab and then continue until the string ends.
This dfa has a final trap state q2 (accepts) and a non-final trap state q3 (rejects).
Find a dfa that accepts all strings on {0, 1}, except those containing the substring
001.
5
Linz Fig. 2.4
6
Linz Figure 2.5 shows a dfa for this example.
Accepts: λ, 0, 00, 01, 010000
Rejects: 001, 000001, 0010101010101
• Construct a dfa.
• Check whether begin/end with “a”.
• Am in final state when second a input.
7
2.1.11 Linz Example 2.6
• Construct a dfa.
8
δ : Q × (Σ ∪ {λ}) → 2Q .
An nfa accepts a string if some possible sequence of moves ends in a final state.
An nfa rejects a string if no possible sequence of moves ends in a final state.
Consider the transition graph for an nfa shown in Linz Figure 2.9.
Note the nondeterminism and the λ-transition.
Note: Here λ means the move takes place without consuming any input symbol.
This is different from accepting an empty string.
Transitions:
9
Linz Fig. 2.8
10
• for (q1 , 0)?
• for (q2 , 0)?
• for (q2 , 1)?
As with dfas, the transition function can be extended so its second argument is
a string.
Requirement: δ ∗ (qi , w) = Qj where Qj is the set of all possible states the
automaton may be in, having started in state qi and read string w.
Linz Definition (Extended Transition Function): For an nfa, the extended
transition function is defined so that δ ∗ (qi , w) contains qj if there is a walk in
the transition graph from qi to qj labelled w.
That is, L(M ) is the set of all strings w for which there is a walk labeled w from
the initial vertex of the transition graph to some final vertex.
Let’s again examine the automaton given in Linz Figure 2.9 (Example 2.8).
This nfa, call it M :
• must end in q0
• L(M ) = {(10)n : n ≥ 0}
11
Linz Fig. 2.9 (Repeated)
• nfa solutions may be simpler than dfa solutions (can convert from nfa to
dfa)
• nondeterminism may model externally influenced interactions (or abstract
more detailed computations)
• When the same input generates the same output for both?
12
2.3.2 Linz Example 2.11
Again consider the nfa represented by the graph in Linz Fig. 2.9. Call this M1 .
13
• Define δN (q, a) = {δD (q, a)}.
Remember from the earlier definitions in these notes and from discrete mathe-
matics:
Procedure nfa_to_dfa
Given a transition graph GN for nfa MN = (QN , Σ, δN , q0 , FN ), construct a
transition graph GD for a dfa MD = (QD , Σ, δD , q0 , FD ). Label each vertex in
GD with a subset of the vertices in GN .
14
2. Repeat the following steps until no more edges are missing from GD :
This, if the loop terminates, it constructs the dfa corresponding to the nfa.
Does the loop terminate?
What is the loop invariant? (This ia a property always that must hold at the
loop test.)
15
Linz Fig. 2.12: An NFA
16
Linz Fig. 2.13: Corresponding DFA
17
Linz Fig. 2.14: An NFA
Convert the nfa shown in Linz Figure 2.14 into an equivalent dfa.
δD ({q0 }, 0) = δN
∗
(q0 , 0) = {q0 , q1 }
δD ({q0 }, 1) = δN
∗
(q0 , 1) = {q1 }
δD ({q0 , q1 }, 0) = δN
∗
(q0 , 0) ∪ δN
∗
(q1 , 0) = {q0 , q1 , q2 }
δD ({q0 , q1 , q2 }, 1) = δN
∗
(q0 , 1) ∪ δN
∗
(q1 , 1) ∪ δN
∗
(q2 , 1) = {q1 , q2 }
The above gives us the partially constructed dfa shown in Linz Figure 2.15.
δD ({q1 }, 0) = δN
∗
(q1 , 0) = {q2 }
δD ({q1 }, 1) = δN
∗
(q1 , 1) = {q2 }
18
δD ({q2 }, 0) = δN
∗
(q1 , 0) = ∅
δD ({q2 }, 1) = δN
∗
(q2 , 1) = {q2 }
δD ({q0 , q1 }, 1) = δN
∗
(q0 , 1) ∪ δN
∗
(q1 , 1) = {q1 , q2 }
δD ({q0 , q1 , q2 }, 0) = δN
∗
(q0 , 0) ∪ δN
∗
(q1 , 0) ∪ δN
∗
(q2 , 0) = {q0 , q1 , q2 }
δD ({q1 , q2 }, 0) = δN
∗
(q1 , 0) ∪ δN
∗
(q2 , 0) = {q2 }
δD ({q1 , q2 }, 1) = δN
∗
(q1 , 1) ∪ δN
∗
(q2 , 1) = {q2 }
Now, the above gives us the dfa shown in Linz Figure 2.16.
19