0% found this document useful (0 votes)
100 views20 pages

DFA Minimization: The Idea: "Minimal"?

Uploaded by

Abhi Shek
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
100 views20 pages

DFA Minimization: The Idea: "Minimal"?

Uploaded by

Abhi Shek
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 20

DFA Minimization: The Idea

“Minimal”?
Minimal number of states.

“Unique”?
Unique up to renaming of states.
I.e., has same shape. Isomorphic.

Will show algorithm & detailed example.


Will outline why algorithm is correct.

1
DFA Minimization: Algorithm Idea

Equate & collapse states having same behavior.


Build equivalence relation on states:
pq  (z*, (p,z)F
̂  (q,z)F)
̂

I.e., iff for every string z, one of the following is true:

z z
p p
or
z z
q q

2
DFA Minimization: Algorithm

Build table to compare each unordered pair of


distinct states p,q.

Each table entry has


 a “mark” as to whether p & q are known to be not
equivalent, and
 a list of entries, recording dependences: “If this
entry is later marked, also mark these.”

3
DFA Minimization: Algorithm

1. Initialize all entries as unmarked & with no dependences.

2. Mark all pairs of a final & nonfinal state.

3. For each unmarked pair p,q & input symbol a:


1. Let r=(p,a), s=(q,a).
2. If (r,s) unmarked, add (p,q) to (r,s)’s dependences,
3. Otherwise mark (p,q), and recursively mark all dependences of newly-
marked entries.

4. Coalesce unmarked pairs of states.

5. Delete inaccessible states.

4
DFA Minimization: Example
0 1

0 1 0
a b c d b
1 0 1
0 1
1 1 0
e f g h c
1 0

0
d

e
1. Initialize table entries:
Unmarked, empty list f

a b c d e f g
5
DFA Minimization: Example
0 1

0 1 0
a b c d b
1 0 1
0 1
1 1 0
e f g h c
1 0

0
d

e
2. Mark pairs of final &
nonfinal states f

a b c d e f g
6
DFA Minimization: Example
0 1

0 1 0
a b c d (b,0) ? (a,0)
0 1 b
1 (b,1) ? (a,1)
0 1
1 1 0
e f g h c
1 0

0
d

e
3. For each unmarked
pair & symbol, … f

a b c d e f g
7
DFA Minimization: Example
0 1

0 1 0
a b c d g ? b Maybe.
0 1 b
1 c ? f No!
0 1
1 1 0
e f g h c
1 0

0
d

e
3. For each unmarked
pair & symbol, … f

a b c d e f g
8
DFA Minimization: Example
0 1

0 1 0
a b c d b
1 0 1
0 1
1 1 0
e f g h c
1 0

0
d

e
3. For each unmarked
pair & symbol, … f

a b c d e f g
9
DFA Minimization: Example
0 1

0 1 0
a b c d (e,0) ? (a,0)
0 1 b
1 (e,1) ? (a,1)
0 1
1 1 0
e f g h c
1 0

0
d

e
3. For each unmarked
pair & symbol, … f

a b c d e f g
10
DFA Minimization: Example
0 1

0 1 0
a b c d h ? b Maybe.
0 1 b
1 f ? f Yes.
0 1
1 1 0
e f g h c
1 0

0
d

e
3. For each unmarked
pair & symbol, … f

h
(a,e)
a b c d e f g
11
DFA Minimization: Example
0 1

0 1 0
a b c d b
1 0 1
0 1
1 1 0
e f g h c
1 0

0
d

e
3. For each unmarked
pair & symbol, … f
(g,a)

g
(g,a)

h
(a,e)
a b c d e f g
12
DFA Minimization: Example
0 1

0 1 0
a b c d b Need to mark.
1 0 1
0 1 So, mark (g,a) also.
1 1 0
e f g h c
1 0

0
d

e
3. For each unmarked
pair & symbol, … f
(g,a)

g
(g,a)

h
(a,e)
a b c d e f g
13
DFA Minimization: Example
0 1

0 1 0
a b c d b
1 0 1
0 1
1 1 0
e f g h c
1 0

0
d

e
3. For each unmarked
pair & symbol, … f
(g,a)

h
(a,e)
a b c d e f g
14
DFA Minimization: Example
0 1

0 1 0
a b c d b
1 0 1
0 1
1 1 0
e f g h c
1 0

0
d

e
4. Coalesce unmarked
pairs of states. f
0 1

0 1 g
ae ae bh c
1 0
bh 0
df 1 h
df g (a,e)
1
0 a b c d e f g
15
DFA Minimization: Example
0 1

0 1 0
a b c d b
1 0 1
0 1
1 1 0
e f g h c
1 0

0
d

e
5. Delete unreachable
states. f
0 1

0 1 g
ae bh c
1 0
None. 0
1 h
df g (a,e)
1
0 a b c d e f g
16
DFA Minimization: Notes

Order of selecting state pairs was arbitrary.


 All orders give same ultimate result.
 But, may record more or fewer dependences.
 Choosing states by working backwards from known non-
equivalent states produces fewest dependences.
Can delete unreachable states initially, instead.
This algorithm: O(n2) time; Huffman (1954), Moore
(1956).
 Constant work per entry: initial mark test & possibly later
chasing of its dependences.
 More efficient algorithms exist, e.g., Hopcroft (1971).

17
DFA Minimization: Correctness

Why is new DFA no larger than old DFA?


Only removes states, never introduces new states.
Obvious.

Why is new DFA equivalent to old DFA?


Only identify states that provably have same behavior.
Could prove xL(M)  xL(M’) by inductions on
derivations.

18
What About NFA Minimization?

This algorithm doesn’t find a unique minimal NFA.

?
Is there a (not necessarily unique) minimal NFA?

? Of course.

19
NFA Minimization

In general, minimal NFA not unique!

Example NFAs for 0+:


0 0

0 0

Both minimal, but not isomorphic.

20

You might also like