finite automata - lecture 4 sections 3.6 - 3 -...
TRANSCRIPT
Finite AutomataLecture 4
Sections 3.6 - 3.7
Robb T. Koether
Hampden-Sydney College
Wed, Jan 21, 2015
Robb T. Koether (Hampden-Sydney College) Finite Automata Wed, Jan 21, 2015 1 / 23
1 Nondeterministic Finite Automata
2 Deterministic Finite Automata
3 Converting an NFA to a DFA
4 Assignment
Robb T. Koether (Hampden-Sydney College) Finite Automata Wed, Jan 21, 2015 2 / 23
Outline
1 Nondeterministic Finite Automata
2 Deterministic Finite Automata
3 Converting an NFA to a DFA
4 Assignment
Robb T. Koether (Hampden-Sydney College) Finite Automata Wed, Jan 21, 2015 3 / 23
Nondeterministic Finite Automata
Definition (Nondeterministic Finite Automaton)A nondeterministic finite automaton, or NFA, consists of
A finite set S of states.An input alphabet Σ.A transition function δ that maps to each state-symbol pair a set ofnext states. The “symbol” may be ε.A set F of final states (or accepting states), where F ⊆ S.
Robb T. Koether (Hampden-Sydney College) Finite Automata Wed, Jan 21, 2015 4 / 23
The Transition Function
Example (The Transition Function)
a | b
a b b1 432
The transition function can be represented as a transition diagram.
Robb T. Koether (Hampden-Sydney College) Finite Automata Wed, Jan 21, 2015 5 / 23
The Transition Function
Example (The Transition Function)
State Next State1 {1,2}2 {3}3 {4}4 ∅
The transition function can also be represented as a transitiontable.
Robb T. Koether (Hampden-Sydney College) Finite Automata Wed, Jan 21, 2015 6 / 23
Acceptance of Strings
A string w is accepted by an NFA if there exists a path through theNFA that w can follow that leads to acceptance.The string is rejected if all possible paths lead to rejection.
In the previous example, is there a path leading to acceptance forthe string bbabb?In the previous example, is there a path leading to rejection for thestring bbabb?How about the string ababab?
Robb T. Koether (Hampden-Sydney College) Finite Automata Wed, Jan 21, 2015 7 / 23
Acceptance of Strings
A string w is accepted by an NFA if there exists a path through theNFA that w can follow that leads to acceptance.The string is rejected if all possible paths lead to rejection.In the previous example, is there a path leading to acceptance forthe string bbabb?
In the previous example, is there a path leading to rejection for thestring bbabb?How about the string ababab?
Robb T. Koether (Hampden-Sydney College) Finite Automata Wed, Jan 21, 2015 7 / 23
Acceptance of Strings
A string w is accepted by an NFA if there exists a path through theNFA that w can follow that leads to acceptance.The string is rejected if all possible paths lead to rejection.In the previous example, is there a path leading to acceptance forthe string bbabb?In the previous example, is there a path leading to rejection for thestring bbabb?
How about the string ababab?
Robb T. Koether (Hampden-Sydney College) Finite Automata Wed, Jan 21, 2015 7 / 23
Acceptance of Strings
A string w is accepted by an NFA if there exists a path through theNFA that w can follow that leads to acceptance.The string is rejected if all possible paths lead to rejection.In the previous example, is there a path leading to acceptance forthe string bbabb?In the previous example, is there a path leading to rejection for thestring bbabb?How about the string ababab?
Robb T. Koether (Hampden-Sydney College) Finite Automata Wed, Jan 21, 2015 7 / 23
Outline
1 Nondeterministic Finite Automata
2 Deterministic Finite Automata
3 Converting an NFA to a DFA
4 Assignment
Robb T. Koether (Hampden-Sydney College) Finite Automata Wed, Jan 21, 2015 8 / 23
Deterministic Finite Automata
Definition (Deterministic Finite Automaton)A determimistic finite automaton, or DFA, is the same as an NFAexcept
The empty string ε is not included in the set of symbols. (Noε-moves.)For each state and for each symbol, there is exactly one nextstate.
Robb T. Koether (Hampden-Sydney College) Finite Automata Wed, Jan 21, 2015 9 / 23
Deterministic Finite Automata
Example (Deterministic Finite Automata)Design a transition diagram for a DFA that accepts
L((a | b)∗abb).
Write the transition table for this DFA.
Robb T. Koether (Hampden-Sydney College) Finite Automata Wed, Jan 21, 2015 10 / 23
Outline
1 Nondeterministic Finite Automata
2 Deterministic Finite Automata
3 Converting an NFA to a DFA
4 Assignment
Robb T. Koether (Hampden-Sydney College) Finite Automata Wed, Jan 21, 2015 11 / 23
NFAs vs. DFAs
In general, it is easier to design an NFA than it is to design a DFA.
Therefore, a common strategy is to design an NFA for a language.But how can a computer simulate an NFA, given that NFAs areinherently nondeterministic?There is an algorithm that will convert an NFA into an equivalentDFA.
Robb T. Koether (Hampden-Sydney College) Finite Automata Wed, Jan 21, 2015 12 / 23
NFAs vs. DFAs
In general, it is easier to design an NFA than it is to design a DFA.Therefore, a common strategy is to design an NFA for a language.
But how can a computer simulate an NFA, given that NFAs areinherently nondeterministic?There is an algorithm that will convert an NFA into an equivalentDFA.
Robb T. Koether (Hampden-Sydney College) Finite Automata Wed, Jan 21, 2015 12 / 23
NFAs vs. DFAs
In general, it is easier to design an NFA than it is to design a DFA.Therefore, a common strategy is to design an NFA for a language.But how can a computer simulate an NFA, given that NFAs areinherently nondeterministic?
There is an algorithm that will convert an NFA into an equivalentDFA.
Robb T. Koether (Hampden-Sydney College) Finite Automata Wed, Jan 21, 2015 12 / 23
NFAs vs. DFAs
In general, it is easier to design an NFA than it is to design a DFA.Therefore, a common strategy is to design an NFA for a language.But how can a computer simulate an NFA, given that NFAs areinherently nondeterministic?There is an algorithm that will convert an NFA into an equivalentDFA.
Robb T. Koether (Hampden-Sydney College) Finite Automata Wed, Jan 21, 2015 12 / 23
Converting an NFA to a DFA
Definition (ε-Closure)Let S be the states of a NFA and let s ∈ S be a state. The ε-closure ofs is the set of all states that are reachable from s (including s itself)through any sequences of ε-moves.
Robb T. Koether (Hampden-Sydney College) Finite Automata Wed, Jan 21, 2015 13 / 23
Converting an NFA to a DFA
Given an NFA, define the states of a DFA to be P(S), i.e., sets ofstates in the NFA.For every state s ∈ P(S) and every symbol a ∈ Σ, the transitionfunction δ(s,a) is the ε-closure of all states in the NFA that arereached from states in s by reading a.That is,
First find all states reached from s by following a-moves.Then find the ε-closure of that set of states.
Robb T. Koether (Hampden-Sydney College) Finite Automata Wed, Jan 21, 2015 14 / 23
Example
Example (Converting an NFA to a DFA)Draw a transition diagram for an NFA that accepts the language ofall strings over {a,b} that either contain an even number of a’s orcontain the substring bab.It is easy to draw if we use ε-moves.
Robb T. Koether (Hampden-Sydney College) Finite Automata Wed, Jan 21, 2015 15 / 23
Example
Example (Converting an NFA to a DFA)
a
b b
2
1
4
3a
5 6 7ab bε
ε
a | b a | b
Robb T. Koether (Hampden-Sydney College) Finite Automata Wed, Jan 21, 2015 16 / 23
Example
Example (Converting an NFA to a DFA)The diagram has 7 states. That is, |S| = 7.Therefore, |P(S)| = 27 = 128.Fortunately, we will use very few of these states.
Robb T. Koether (Hampden-Sydney College) Finite Automata Wed, Jan 21, 2015 17 / 23
Example
Example (Converting an NFA to a DFA)
State ε-closure1 {1,2,4}2 {2}3 {3}4 {4}5 {5}6 {6}7 {7}
Robb T. Koether (Hampden-Sydney College) Finite Automata Wed, Jan 21, 2015 18 / 23
Example
Example (Converting an NFA to a DFA)The start state is ε-closure(1) = {1,2,4}.The transition function, for example, includes
δ({1,2,4},a) = ε-closure({3,4}) = {3,4}δ({1,2,4},b) = ε-closure({2,4,5}) = {2,4,5}
Work out the remaining transitions.
Robb T. Koether (Hampden-Sydney College) Finite Automata Wed, Jan 21, 2015 19 / 23
Example
Example (Converting an NFA to a DFA)The start state is ε-closure(1) = {1,2,4}.The transition function, for example, includes
δ({1,2,4},a) = ε-closure({3,4}) = {3,4}δ({1,2,4},b) = ε-closure({2,4,5}) = {2,4,5}
Work out the remaining transitions.
Robb T. Koether (Hampden-Sydney College) Finite Automata Wed, Jan 21, 2015 19 / 23
Example
Example (Converting an NFA to a DFA)
a
a124 34
a
24
345
246245
346 3457 2467 2457
347 247
3467
b
a
b
a
b
a
bbb
a
b
a b
a
b
a
ba b
ab
b
a
Robb T. Koether (Hampden-Sydney College) Finite Automata Wed, Jan 21, 2015 20 / 23
Example
Example (Converting an NFA to a DFA)
a124 34
24
345
246245
346
b
a
b
a a
b
b
a
ab
b
a b
a | b
A reduced DFA
Robb T. Koether (Hampden-Sydney College) Finite Automata Wed, Jan 21, 2015 21 / 23
Example
Example (Converting an NFA to a DFA)
a1 2
5
3
64
7
b
a
b
a a
b
b
a
ab
b
a b
a | b8
Relabel the states
Robb T. Koether (Hampden-Sydney College) Finite Automata Wed, Jan 21, 2015 21 / 23
Outline
1 Nondeterministic Finite Automata
2 Deterministic Finite Automata
3 Converting an NFA to a DFA
4 Assignment
Robb T. Koether (Hampden-Sydney College) Finite Automata Wed, Jan 21, 2015 22 / 23