Sei sulla pagina 1di 29

Equivalence and Minimization of Deterministic Finite Automata

Joseph Southern CPSC 627 Spring 2003

Outline
Introduction Testing of equivalence of states
Definitions

Table-filling algorithm Minimization of DFAs Questions

Introduction
Basic Idea of Minimization of DFAs We can take any DFA and find an equivalent DFA that has the minimum number of states.
In fact, this DFA is essentially unique: given any two minimum state DFAs that are equivalent, we can always find a way to rename the states so that the two DFA become the same.

Introduction
Basic Idea 1. Find equivalent states
1. Use table-filling algorithm

2. Partition equivalent states derived from table-filling algorithm into blocks and condense DFA.

Definitions
Equivalent When two distinct states p and q can be replaced by a single state that behaves like both p and q. Distinguishable When two states are not equivalent. That is, state p is distinguishable from state q if there is at least one string [ such that one of H(p,[) and H(q,[) is accepting, and the other is not accepting.

Table-filling Algorithm
1. Initialize all entries as unmarked and with no dependencies. 2. Mark all pairs of a accepting and non-accepting state. 3. For each unmarked pair p,q and input symbol a: 1. Let r = H(p,a), s = H(q,a). 2. If (r,s) unmarked, add (p,q) to (r,s)s dependencies, 3. Otherwise mark (p,q), and recursively mark all dependencies of newly-marked entries.

Table-filling Example
0 1

a e

0 1 1

b1
0

0 1

c g
0

0 1 1 0

d h

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

f
1

1. Initialize table entries: Unmarked, empty list

a e

0 1 1

b1
0

0 1

c g
0

0 1 1 0

d h

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

f
1

2. Mark pairs of final & non-final states

a e

0 1 1

b1
0

0 1

c g
0

0 1 1 0

d h

b c d e f g h

(b,0) |? (a,0) (b,1) |? (a,1)

f
1

3. For each unmarked pair & symbol . . .

a b c d e

a e

0 1 1

b1
0

0 1

c g
0

0 1 1 0

d h

b c d e f g h

(b,0) |? (a,0) (b,1) |? (a,1) g |? b Maybe. c |? f No

f
1

3. For each unmarked pair & symbol . . .

a b c d e

(d,0) |? (a,0) (d,1) |? (a,1) Mark It


0 1

c |?b No g |?f Maybe

a e

0 1 1

b1
0

0 1

c g
0

0 1 1 0

d h

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

f
1

3. For each unmarked pair & symbol . . .

a e

0 1 1

b1
0

0 1

c g
0

0 1 1 0

d h

b c d e f g h

(e,0) |? (a,0) (e,1) |? (a,1)

f
1

3. For each unmarked pair & symbol . . .

a b c d e

a e

0 1 1

b1
0

0 1

c g
0

0 1 1 0

d h

b c d e f g h

h |? b Maybe. f |? f Yes

f
1

3. For each unmarked pair & symbol . . .

(a,e)

a b c d e

(f,0) |? (a,0) (f,1) |? (a,1)

c |?b No g |?f Maybe

a e

0 1 1

b1
0

0 1

c g
0

0 1 1 0

d h

b c d e f g h

f
1

3. For each unmarked pair & symbol . . .

(a,e)

a b c d e

(g,0) |? (a,0) (g,1) |? (a,1)

g |?b Maybe e |?f Maybe

a e

0 1 1

b1
0

0 1

c g
0

0 1 1 0

d h

b c d e f g h

f
1

3. For each unmarked pair & symbol . . .

(a,e)

a b c d e

(g,0) |? (a,0) (g,1) |? (a,1)

g |?b Maybe e |?f Maybe

a e

0 1 1

b1
0

0 1

c g
0

0 1 1 0

d h

b c d e f g h

f
1

(g,a) (g,a) (a,e)

3. For each unmarked pair & symbol . . .

a b c d e

(h,0) |? (a,0) (h,1) |? (a,1) MARK IT


0 1

g |?b Maybe c |?f Not

a e

0 1 1

b1
0

0 1

c g
0

0 1 1 0

d h

b c d e f g h

f
1

(g,a) (g,a) (a,e)

3. For each unmarked pair & symbol . . .

a b c d e

(d,0) |? (b,0) (d,1) |? (b,1) MARK IT


0 1

c |?g No g |?c No

a e

0 1 1

b1
0

0 1

c g
0

0 1 1 0

d h

b c d e f g h

f
1

(g,a) (g,a) (a,e)

3. For each unmarked pair & symbol . . .

a b c d e

(e,0) |? (b,0) (e,1) |? (b,1) MARK IT


0 1

h |?g Maybe f |?c No

a e

0 1 1

b1
0

0 1

c g
0

0 1 1 0

d h

b c d e f g h

f
1

(g,a) (g,a) (a,e)

3. For each unmarked pair & symbol . . .

a b c d e

(f,0) |? (b,0) (f,1) |? (b,1) MARK IT


0 1

c |?g No g |?c No

a e

0 1 1

b1
0

0 1

c g
0

0 1 1 0

d h

b c d e f g h

f
1

(g,a) (g,a) (a,e)

3. For each unmarked pair & symbol . . .

a b c d e

(g,0) |? (b,0) g |?g Yes (g,1) |? (b,1) e |?c No MARK IT Recursively go back and mark (g,a).
0 1

a e

0 1 1

b1
0

0 1

c g
0

0 1 1 0

d h

b c d e f g h

f
1

(g,a) (g,a) (a,e)

3. For each unmarked pair & symbol . . .

a b c d e

(g,0) |? (b,0) g |?g Yes (g,1) |? (b,1) e |?c No MARK IT Recursively go back and mark (g,a).
0 1

a e

0 1 1

b1
0

0 1

c g
0

0 1 1 0

d h

b c d e f g h

f
1

(g,a) (g,a) (a,e)

3. For each unmarked pair & symbol . . .

a b c d e

(h,0) |? (b,0) (h,1) |? (b,1) Dont Mark It


0 1

g |?g Yes c |?c Yes

a e

0 1 1

b1
0

0 1

c g
0

0 1 1 0

d h

b c d e f g h

f
1

(g,a) (g,a) (a,e)

3. For each unmarked pair & symbol . . .

a b c d e

a e

0 1 1

b1
0

0 1

c g
0

0 1 1 0

d h

b c d e f g h

f
1

3. For each unmarked pair and symbol, . . .

(a,e)

a b c d e

Minimization of DFA
Partition equivalent states together.
b c d e f g h a b c d e f g

{a,e}, {b,h}, {c}, {df}, {g}

a|e b|h d|f

ae
1 1

bh
0 1

1 0

df

g
0

a e

0 1 1

b1
0

0 1

c g
0

0 1 1 0

d h

f
1

b c d e f g h

{a,e}, {b,h}, {c}, {df}, {g}


0 1 1 0

ae
1

0 1

bh df
0 1

(a,e)

g
0

a b c d e

Citations
J. E. Hopcroft, R. Motwani, and J. D. Ullman. "Introduction to Automata Theory, Language, and Computation". Addison-Wesley, 2nd edition, 2001. http://www.cs.yorku.ca/course_archive/200 1-02/S/2001B/lectures/gh.pdf

Questions?

Potrebbero piacerti anche