dfa minimization

Post on 21-Nov-2014

292 Views

Category:

Documents

2 Downloads

Preview:

Click to see full reader

DESCRIPTION

Algorithm for minimizing DFA

TRANSCRIPT

DFA minimization

Example• Construct a DFA over alphabet {0, 1} that

accepts those strings that end in 111

• This is big, isn’t there a smaller DFA for this?

0

1

……

……

q

q

q

q

q

q

q

q

q

q

q

0

1

0

1

0

1

1

1

1

1

0

Smaller DFA

10

00

0

1q q q q1 1

Can we do it with 3 states?

Even smaller DFA?• Suppose we had a 3 state DFA M for L

… let’s imagine what happens when:

• By the pigeonhole principle, on two of these inputs M ends in the same state

Minputs:

, 1, 11, 111

Pigeonhole principle

• Here, balls are inputs, bins are states:

Suppose you are tossing m balls into n bins, and m > n. Then two balls end up in the same bin.

If you have a DFA with n states and you run it on m inputs, and m > n, then two inputs end up in same state.

A smaller DFA

• Suppose M ends up in the same state after reading inputs x = 1 and y = 11

• Then after reading one more 1– The state of x1 = 11 should be rejecting– The state of y1 = 111 should be accepting

… but they are both the same state!

Minputs:

, 1, 11, 111

1, 11

11, 111

“ends in 111”

A smaller DFA

• Suppose M ends up in the same state after reading inputs x = and y = 1

• Then after reading 11– The state of x1 = 11 should be rejecting– The state of y1 = 111 should be accepting

… but they are both the same state!

Minputs:

, 1, 11, 111

, 1

11, 111

“ends in 111”

No smaller DFA!• After looking at all possible pairs for x, y, x ≠ y

we conclude that

• So, this DFA is minimal

There is no DFA with 3 states for L

1q q q q1 1 1

0

00

0

(, 1) (, 11) (, 111) (1, 11) (1, 111) (11, 111)

DFA minimization

We will show how to turn any DFA for L into the minimal DFA for L

0

1

q

q

q

q

q

q

q

q

q

q

q

01

01

0

1

1

1

1

1

0

1

q

q

q

q

1

1

1

00 0

0

Minimal DFAs and distinguishable states

• First, we have to understand minimal DFAs:

10

00

0

1q q q q1 1

reject accept

minimal DFA every pair of states is distinguishable

Distinguishable states• Two states q and q’ are distinguishable if

q

q’

w1

w1

w2

w2

wk

wk

wk-1

wk-1

on the same continuation string w1w2...wk, one accepts, but the other rejects

reject

accept

Examples of distinguishable states

distinguishable by 01(q0, q2)(q0, q3)

(q0, q1)

(q1, q3)(q2, q3)

(q1, q2)

distinguishable by 1distinguishable by

distinguishable by 1distinguishable by

distinguishable by

0 0

1q q q q0 1

0 1 1

DFA is minimal

Examples of distinguishable states

distinguishable by

q

q

q

q

0

1

0

1

0, 1

0, 1

q0

q

q

0

1

0, 1

0, 1

(q1, q3)(q2, q3)

(q0, q3)

(q0, q2)(q0, q1)

(q1, q2)

distinguishable by

distinguishable by

distinguishable by 0distinguishable by 0indistinguishable

indistinguishable pairs can be merged

Examples of distinguishable states

distinguishable by

(q1, q2)(q0, q3)

(q0, q2)

(q0, q1)(q2, q3)

(q1, q3)

distinguishable by

distinguishable by

distinguishable by

indistinguishable

indistinguishable

q

q

q

q

1

0, 1

0, 1

0, 1

0

qq0, 1

0, 1

Finding (in)distinguishable states

Rule 1:

Rule 2:

q q’If q is accepting and q’ is rejectingMark (q, q’) as distinguishable (x)x

q1 q1’x

xq2 q2’

a a If (q1, q1’) are marked,Mark (q2, q2’) as distinguishable (x)

Rule 3: Unmarked pairs are indistinguishableMerge them together

Example of DFA minimization

0

1q

q

q

q

q

q

q

01

01

1

0

01

1

0

0

1

q

q

q

q

q

q

qq q q qq

Example of DFA minimization

0

1q

q

q

q

q

q

q

01

01

1

0

01

1

0

0

1

x x x x x x

q

q

q

q

q

q

qq q q qq

q11 is distinguishable from all other states

Example of DFA minimization

0

1q

q

q

q

q

q

q

01

01

1

0

01

1

0

0

1

x

x

x

x

x

x

x x x x

q

q

q

q

q

q

qq q q qq

q1 is distinguishable from q, q0, q00, q10

On transition 1, they go to distinguishable states

Example of DFA minimization

0

1q

q

q

q

q

q

q

01

01

1

0

01

1

0

0

1

x

x

x

x

x

x

x

x

x

x

x

x

x x

q

q

q

q

q

q

qq q q qq

q01 is distinguishable from q, q0, q00, q10

On transition 1, they go to distinguishable states

Example of DFA minimization

0

1q

q

q

q

q

q

q

01

01

1

0

01

1

0

0

1

A

x

A

x

A

x

x

A

x

A

x

x

B

x

x

x

A

x

x

x x

q

q

q

q

q

q

qq q q qq

Merge states not marked distinguishable q, q0, q00, q10 are equivalent → group A q1, q01 are equivalent → group B q11 cannot be merged → group C

A

B

C

Example of DFA minimization

0

1q

q

q

q

q

q

q

01

01

1

0

01

1

0

0

1

A

x

A

x

A

x

x

A

x

A

x

x

B

x

x

x

A

x

x

x x

q

q

q

q

q

q

qq q q qq

1q q qC1 1

0

00

minimized DFA:

A

B

C

Food for thought• Why does method find all distinguishable pairs?

q

q’

w1

w1

w2

w2

wk

wk

wk-1

wk-1

xxxx

Because we work backwards

Food for thought• Why are there no inconsistencies when we merge?

Aq3

q7

q1

B

q5

q2

C

q6

a

a

Because we only merge indistinguishable states

w

w

Food for thought• Why is there no smaller DFA?

Mq

q’

v

v’

smaller DFA M’

q’’v, v’

Suppose there is

By the pigeonhole principle this must happen:

Food for thought• Why is there no smaller DFA?

But then

M smaller DFA M’q

q’

v

v’

q’’v, v’

w

w?

w

Every pair of statesis distinguishable

q’’ cannot exist!

top related