Finite Automata & Regular Languages

Download Report

Transcript Finite Automata & Regular Languages

Nondeterministic Finite
Automata
CS 130: Theory of Computation
HMU textbook, Chapter 2
(Sec 2.3 & 2.5)
NFAs:
Nondeterministic Finite Automata

Same as a DFA, except:



On input a, state q may have more than one
transition out, implying the possibility of multiple
choices when processing an input symbol
On input a, state q may have no transition out,
implying the possibility of “being stuck”
A string w is acceptable as long as there
exists an admissible state sequence for w
NFAs

A nondeterministic finite automaton M is a
five-tuple M = (Q, , , q0, F), where:





Q is a finite set of states of M
 is the finite input alphabet of M
: Q    power set of Q, is the state transition
function mapping a state-symbol pair to a subset
of Q
q0 is the start state of M
F  Q is the set of accepting states or final states
of M
Example NFA

NFA that recognizes the language of
strings that end in 01
0,1
q0
0
q1
1
note: (q0,0) = {q0,q1}
(q1,0) = {}
q2
Exercise:
draw the
complete
transition table
for this NFA
^ definition for an NFA



^: Q X *  power set of Q
^(q, ) = {q}
^(q, w), w = xa
(where x is a string and a is a symbol)
is defined as follows:


Let ^(q, x) = {p1,p2,…pk}
Then, ^(q, w) =  (pi, a)
Language recognized by an NFA

A string w is accepted by an NFA M if
^(q0, w)  F is non-empty



Note that ^(q0, w) represents a subset of states
since the automaton is nondeterministic
Equivalent definition: there exists an admissible
state sequence for w in M
The language L(M) recognized by an NFA is
the set of strings accepted by M

L(M) ={ w | ^(q0, w)  F is non-empty }
Converting NFAs to DFAs

Given a NFA, M = (Q, , , q0, F), build
a DFA, M’ = (Q’, , ’, {q0}, F’) as
follows.



Q’ contains all subsets S of states in Q.
The initial state of M’ is the set containing
q0
F’ is the set of all subsets of Q that contain
at least one element in F (equivalently, the
subset contains at least one final state)
Converting NFAs to DFAs

’ is determined by putting together, for
each state in the subset and each symbol,
all states that may result from a transition:
’(S, a) =
 (q, a)
qS

May remove “unreachable” states in Q’
Example conversion

NFA
0,1
0
q0

1
q1
q2
DFA
1
{q0 }
0
0
{q0,q1}
1
{q0,q2}
0
1
NFA with -transitions

NFA that allows the transition of an
empty string from a state


Jumping to a state is possible even without
input
Revision on NFA definition simply allows
the  “symbol” for 
NFA with -transitions

A nondeterministic finite automaton with transitions (or -NFA) is a five-tuple
M = (Q, , , q0, F), where:





Q is a finite set of states of M
 is the finite input alphabet of M
: Q  ( + )  power set of Q, is the state
transition function mapping a state-symbol pair to
a subset of Q
q0 is the start state of M
F  Q is the set of accepting states or final states
of M
Converting -NFAs to NFAs





Task: Given an
-NFA M = (Q, , , q0, F), build a
NFA M’ = (Q, , ’, q0, F’)
Need to eliminate -transitions
Need epsilon closure concept
Add transitions to enable transitions
previously allowed by the -transitions
Note: the conversion process in the textbook
instead builds a DFA from an -NFA

The conversion described in these slides is simpler
Epsilon closure



In an NFA M, let q  Q
ECLOSE(q) represents all states r that can be
reached from q using only -transitions
Recursive definition for ECLOSE



If (q, ) is empty, ECLOSE(q) = {q}
Else, Let (q, ) = {r1, r2,…, rn}.
ECLOSE(q) = ECLOSE(ri)  {q}
Note: check out constructive definition in the
textbook
Additional transitions




Suppose ECLOSE(q) = {r1, r2,…, rn }.
For each transition from state ri to
state sj on (non-epsilon) symbol a,
add a transition from q to sj on symbol a
That is,
’(q, s) = (q, s)  states resulting from the
additional transitions
Initially set F’ = F.
If (q, ) includes a state in F’, add q to F’
Equivalence of Finite Automata



Conversion processes between
DFAs, NFAs, and -NFAs show that no
additional expressive capacity (except
convenience) is introduced by nondeterminism or -transitions
All models represent regular languages
Note: possible exponential explosion of
states when converting from NFA to DFA
Closure of Regular Languages
under certain operations





Union
Complementation
Intersection
Concatenation
L1  L2
L1
L1  L2
L1L2
Goal: ensure a FA can be produced
from the FAs of the “operand”
languages
Finite Automata with Output

Moore Machines


Mealy Machines


Output symbol for each state encountered
Output symbol for each transition
encountered
Exercise: formally define Moore and
Mealy machines
Next: Regular Expressions


Defines languages in terms of symbols
and operations
Example


(01)* + (10)* defines all even-length
strings of alternating 0s and 1s
Regular expressions also model regular
languages and we will demonstrate
equivalence with finite automata