CS5371 Theory of Computation: Lecture 6: Automata Theory IV (Regular Expression NFA DFA)
CS5371 Theory of Computation: Lecture 6: Automata Theory IV (Regular Expression NFA DFA)
Theory of Computation
Lecture 6: Automata Theory IV
(Regular Expression = NFA = DFA)
Objectives
•Give formal definition of Regular
Expression
•Show that the power of Regular
Expression = the power of NFA = the
power of DFA
–in terms of describing a language
Regular Expression
(Formal Definition)
•We say R is a regular expression if R is
– a for some a in the alphabet , or
– , or Don’t confuse with ;
– ;, or
– (R1 [ R2), where R1 and R2 are regular
expressions, or
– (R1 o R2), where R1 and R2 are regular
expressions, or
– (R1*), where R1 is a regular expression
True or False?
•R [ ; = R True
•R o = R True
•R [ = R False
•R o ; = R False
Equivalence with NFA
(Part I)
Lemma: If a language is described by a
regular expression, then it is regular.
a
(2) R = . Then L(R) = {
}, and the
following NFA recognizes L(R)
R = (ab [ a)*
a
a
b
b
a b
ab
ab [ a
a b
a
(ab [ a)*
a b
a
Equivalence with NFA
(Part II)
Lemma: If a language is regular, it can be
described by a regular expression.
a*
ab [ ba
;
(aa)*
b* qaccept
ab
b
GNFA
•Similar to NFA, except that the labels on
the transition arrows are regular
expressions (instead of a character or )
•To move along a transition arrow, we read
blocks of characters such that it matches
the description of the regular expression
on that arrow
•An input string is accepted if there is a
way to read the input string such that the
GNFA is in an accepting state after
processing the whole input string
GNFA (further assumptions)
•Only one start state qstart, with no
incoming arrows
•Only one accepting state qaccept, with
no outgoing arrows
•Each state (except qstart and qaccept)
has exactly one arrow going to every
other state and also itself
Back to the Proof:
Converting DFA to GNFA
•Add a new start state, with arrow to the
original start state
•Add a new accept state, with arrow from
each of the original accept state
•If original arrow has multiple labels, we
replace this with a new arrow whose label
is a regular expression formed by the union
of the labels
•If originally no arrow between two states,
we add a new arrow whose label is ;
Converting DFA to GNFA
(Example)
a a
b b
a a
b
a
b
a
b b
DFA GNFA
Converting GNFA
to Regular Expression
•We iteratively remove one state in
GNFA, such that after each state
removal, the new GNFA obtained will
recognize the same language as the
previous one
•When the number of states of GNFA
is 2, we have the regular expression
(why??)
How to remove a state?
•Select any state q except qstart and
qaccept
•Remove q
–To compensate the absence of q, the
new label on the arrow from qi to qj
becomes a regular expression that
describes all strings that would take the
GNFA to go from qi to qj, either directly
or via q
How to remove a state?
R4
qi qj
R4 [ (R1) (R2)*(R3)
qi qj
R1 R3
q
R2
?
b
a
?
b
b
?
a aa [ b
?
ab
b ba [ a ? ?
bb ?