COMS W3261
Computer Science Theory
Lecture 6: September 28, 2009
Constructing a Regular Expression from a DFA
1. Outline
- Review
- From DFA's to regular expressions by Kleene's algorithm
- From DFA's to regular expressions by eliminating states
2. Review
- In past lectures we have shown DFA's, NFA's, and ε-NFA's are
equivalent in definitional capability.
- Today we show regular expressions are equivalent in definitional
capability to finite automata.
3. From DFA's to Regular Expressions by Kleene's algorithm
- Given a DFA A, Kleene's algorithm constructs a regular expression
R from A such that L(R) = L(A).
- Suppose the states of A are numbered 1, 2, ..., n.
- Kleene's algorithm constructs a set of regular expressions
R[i,j,k] representing all paths from state i
to state j with no intermediate node in the path numbered higher
than k:
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++)
if (i != j)
if (there are transitions from state i to state j labeled a1, a2, ..., ak)
R[i,j,0] = a1 + a2 + ... + ak;
else
R[i,j,0] = ∅;
else if (i == j)
if (there are transitions from state i to state i labeled a1, a2, ..., ak)
R[i,i,0] = &epsilon + a1 + a2 + ... + ak;
else
R[i,i,0] = ε;
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++)
for (k = 1; k <= n; k++)
R[i,j,k] = R[i,j,k-1] + R[i,k,k-1](R[k,k,k-1])*R[k,j,k-1];
Assuming the start state is 1, the regular expression for the DFA A is then
the sum (union) of all expressions R[1,j,n] such that j is
a final state.
Note that Kleene's algorithm for constructing a regular expression from
a DFA reduces to the transitive closure algorithm (Warshall's algorithm)
and to the all-pairs shortest paths algorithm (Floyd's algorithm)
for directed graphs.
Example 3.5, HMU, pp. 95-97.
4. From DFA's to RE's by Eliminating States
- Kleene's algorithm gives us a mechanical way to construct
a regular expression from a DFA, or for that matter, from any NFA
or ε-NFA.
- Another approach that avoids duplicating work is to eliminate
states, one at a time, from the DFA using the procedure
outlined in Section 3.2.2 of HMU.
- Example 3.6, HMU, pp. 101-102.
- You can see an expanded treatment of state elimination
with more examples in pp. 583-588 of Chapter 10 of
Aho and Ullman, Foundations of Computer Science.
5. Practice Problems
- Consider the DFA D with:
- Q = {
1, 2, 3}
- Σ = {
a, b}
- δ:
State |
Input Symbol |
a |
b |
1 |
2 |
1 |
2 |
3 |
1 |
3 |
3 |
2 |
- Start state:
1
- F = {
3}
- a) Use Kleene's algorithm to construct a regular expression for L(D).
Simplify your expressions as much as possible at each stage.
- b) Construct a regular expression for L(D) by eliminating state 2.
- HMU, Exercise 3.2.3, p. 107.
6. Reading Assignment
aho@cs.columbia.edu