DFA minimization The Chinese University of Hong Kong Fall 2011

Slides:



Advertisements
Similar presentations
CS2303-THEORY OF COMPUTATION
Advertisements

CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Properties.
Reducing DFA’s Section 2.4. Reduction of DFA For any language, there are many DFA’s that accept the language Why would we want to find the smallest? Algorithm:
CSE 202 – Formal Languages and Automata Theory 1 REGULAR LANGUAGE.
CS5371 Theory of Computation
Fall 2006Costas Busch - RPI1 Deterministic Finite Automata And Regular Languages.
Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Fall 2008.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Regular.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Nondeterminism.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Limitations.
1 CSCI 3130: Formal Languages and Automata Theory Tutorial 4 Hung Chun Ho Office: SHB 1026 Department of Computer Science & Engineering.
1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY For next time: Read 2.1 & 2.2.
Transparency No. 8-1 Formal Language and Automata Theory Chapter 8 DFA state minimization (lecture 13, 14)
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong DFA minimization.
Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong Fall 2011.
CSCI 3130: Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong Interaction,
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong DFA to regular.
Tutorial CSC3130 : Formal Languages and Automata Theory Haifeng Wan ( )
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Ambiguity.
Fall 2006Costas Busch - RPI1 Deterministic Finite Automaton (DFA) Input Tape “Accept” or “Reject” String Finite Automaton Output.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Closure.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong NFA to DFA.
Decidable Questions About Regular languages 1)Membership problem: “Given a specification of known type and a string w, is w in the language specified?”
DFA Minimization 1 2 Equivalent States Consider the accept states c and g. They are both sinks meaning that any string which ever reaches them is guaranteed.
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Text search.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Turing Machines.
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong NFA to.
CSCI 3130: Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong Interaction,
CSCI 3130: Formal languages and automata theory Tutorial 3 Chin.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong DFA minimization.
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
CSCI 3130: Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong Limitations.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Normal forms.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AA.
CSE 202 – Formal Languages and Automata Theory 1 REGULAR EXPRESSION.
CSCI 3130: Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong Decidable.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Undecidable.
CSCI 3130: Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong Polynomial.
Fall 2004COMP 3351 Finite Automata. Fall 2004COMP 3352 Finite Automaton Input String Output String Finite Automaton.
Nondeterminism The Chinese University of Hong Kong Fall 2011
Formal Language & Automata Theory
More variants of Turing Machines
Polynomial time The Chinese University of Hong Kong Fall 2010
G. Pullaiah College of Engineering and Technology
Undecidable problems for CFGs
Undecidable problems for CFGs
Reducibility The Chinese University of Hong Kong Fall 2010
Pushdown automata and CFG ↔ PDA conversions
LR(1) grammars The Chinese University of Hong Kong Fall 2010
More on DFA minimization and DFA equivalence
Non-Deterministic Finite Automata
Finite Automata.
NFAs, DFAs, and regular expressions
Decidable and undecidable languages
NP-completeness The Chinese University of Hong Kong Fall 2008
More undecidable languages
LR(1) grammars The Chinese University of Hong Kong Fall 2011
NFA to DFA conversion and regular expressions
More on NP-completeness
Non-regular languages
Non-regular languages
Regular Language Equivalence and DFA Minimization
Pushdown automata The Chinese University of Hong Kong Fall 2011
More undecidable languages
Text search and closure properties
Normal forms and parsing
Chapter # 5 by Cohen (Cont…)
Non Deterministic Automata
Nondeterminism The Chinese University of Hong Kong Fall 2010
Presentation transcript:

DFA minimization The Chinese University of Hong Kong Fall 2011 CSCI 3130: Automata theory and formal languages DFA minimization Andrej Bogdanov http://www.cse.cuhk.edu.hk/~andrejb/csc3130

Example L = {w: w ends in 111} Isn’t there a smaller one?

Smaller DFA L = {w: w ends in 111} Can we do it with 3 states? 1 q0 q1 1 q0 q1 q2 q3 1 Can we do it with 3 states?

Even smaller DFA? L = {w: w ends in 111} Suppose we had a 3 state DFA for L There are 4 inputs but 3 states On two of these inputs M ends in the same state M inputs: e, 1, 11, 111

Pigeonhole principle Suppose you are tossing 4 balls into 3 bins. Then two balls end up in the same bin. Take 4 inputs and feed them into a 3 state DFA. Then two inputs end up in the same state.

✘ A smaller DFA L = {w: w ends in 111} Suppose inputs x = 1, y = 11 lead to same state Then after reading one more 1 The state of x1 = 11 should be rejecting The state of y1 = 111 should be accepting M 1, 11 inputs: 1 e, 1, 11, 111 11, 111 “ends in 111” ✘

✘ A smaller DFA L = {w: w ends in 111} Suppose inputs x = e, y = 1 lead to same state Then after reading 11 The state of x1 = 11 should be rejecting The state of y1 = 111 should be accepting M e, 1 inputs: 1 e, 1, 11, 111 11, 111 ✘

No smaller DFA! After looking at all possible pairs (x, y) we conclude that So, this DFA is minimal (e, 1) (e, 11) (e, 111) (1, 11) (1, 111) (11, 111) There is no DFA with 3 states for L 1 q0 q1 q2 q3

DFA minimization 1 … qe q0 q1 q00 q10 q01 q11 q000 q001 q101 q111 1 q0 q1 q2 q3 We now show how to turn any DFA for L into the minimal DFA for L

Minimal DFAs and distinguishable states First, we have to understand minimal DFAs: reject accept 1 1 1 q0 q1 q2 q3 1 every pair of states is distinguishable minimal DFA

Distinguishable states Two states q and q’ are distinguishable if accept w1 w2 wk-1 wk … q reject w1 w2 wk-1 wk … q’ on the same continuation string w1w2...wk, one accepts, but the other rejects

Examples of distinguishable states 1 1 1 1 q0 q1 q2 q3 (q0, q1) distinguishable by 01 (q0, q2) distinguishable by 1 (q0, q3) distinguishable by e DFA is minimal (q1, q2) distinguishable by 1 (q1, q3) distinguishable by e (q2, q3) distinguishable by e

Examples of distinguishable states q0 q1 q2 q3 1 0, 1 q01 q2 q3 1 0, 1 (q0, q3) distinguishable by e (q1, q3) distinguishable by e indistinguishable pairs can be merged (q2, q3) distinguishable by e (q1, q2) distinguishable by 0 (q0, q2) distinguishable by 0 (q0, q1) indistinguishable

Examples of distinguishable states q0 q2 0, 1 q01 q23 0, 1 1 q1 0, 1 q3 0, 1 (q0, q2) distinguishable by e (q1, q2) distinguishable by e (q0, q3) distinguishable by e (q1, q3) distinguishable by e (q0, q1) indistinguishable (q2, q3) indistinguishable

Finding (in)distinguishable states If q is accepting and q’ is rejecting Mark (q, q’) as distinguishable (x) Rule 1: q x q’ q1 x q1’ q2 q2’ a If (q1, q1’) are marked, Mark (q2, q2’) as distinguishable (x) Rule 2: x Rule 3: Unmarked pairs are indistinguishable Merge them into groups

Example of DFA minimization q0 q00 q1 q0 1 1 q01 q00 qe 1 q01 q10 1 1 q10 q1 1 q11 q11 qe q0 q1 q00 q01 q10 1

Example of DFA minimization q0 q00 q1 q0 1 1 q01 q00 qe 1 q01 q10 1 1 q10 q1 1 q11 q11 x x x x x x qe q0 q1 q00 q01 q10 1  q11 is distinguishable from all other states

Example of DFA minimization q0 q00 q1 1 q0 1 1 q01 q00 qe 1 q01 q10 1 1 q10 q1 1 q11 q11 x x x x x x qe q0 q1 q00 q01 q10 1  Look at pair qe, q0 Neither (q0, q00) nor (q1, q01) are distinguishable

Example of DFA minimization q0 q00 q1 x q0 1 1 q01 q00 qe 1 1 q01 q10 1 1 q10 q1 1 q11 q11 x x x x x x qe q0 q1 q00 q01 q10 1  Look at pair qe, q1 (q1, q11) is distinguishable

Example of DFA minimization q0 q00 q1 x x q0 1 1 q01 q00 x qe 1 q01 x x x q10 1 1 q10 x x q1 1 q11 q11 x x x x x x qe q0 q1 q00 q01 q10 1  After going thru the whole table once Now we make another pass

Example of DFA minimization q0 q00 q1 x x 1 q0 1 1 q01 q00 x qe 1 q01 x x x q10 1 1 q10 x x q1 1 q11 q11 x x x x x x qe q0 q1 q00 q01 q10 1  Look at pair qe, q0 Neither (q1, q00) nor (q1, q01) are distinguishable

Example of DFA minimization q0 q00 q1 x x q0 1 1 q01 q00 x 1 qe 1 q01 x x x q10 1 1 q10 x x q1 1 q11 q11 x x x x x x qe q0 q1 q00 q01 q10 1  Look at pair qe, q00 Neither (q0, q00) nor (q1, q01) are distinguishable

Example of DFA minimization q0 q00 q1 x x q0 1 1 q01 q00 x qe 1 q01 x x x q10 1 1 q10 x x q1 1 q11 q11 x x x x x x qe q0 q1 q00 q01 q10 1  In the second pass, nothing changes So we are ready to apply Rule 3

Example of DFA minimization q0 q00 q1 x x q0 q01 q00 x qe q01 x x x q10 q10 x x q1 q11 q11 x x x x x x qe q0 q1 q00 q01 q10  Merge unmarked pairs into groups

Example of DFA minimization q0 A q00 q1 x x q0 A q01 q00 A A x qe q01 x x B x q10 q10 A A x A x q1 B q11 q11 x x x x x x C qe q0 q1 q00 q01 q10  Merge unmarked pairs into groups

Example of DFA minimization q0 A q00 q1 x x q0 A 1 1 q01 q00 A A x qe 1 q01 x x B x q10 1 1 q10 A A x A x q1 1 B q11 q11 x x x x x x C qe q0 q1 q00 q01 q10 1 1 qA qB qC minimized DFA:

Example of DFA minimization 1 qA qB qC How do we know this DFA is minimal? 1 e qB qC qA Answer: All pairs are distinguishable

Why it works Why do we end up finding all distinguishable pairs? wk-1 wk … q x x x x w1 w2 wk-1 wk … q’ Because we work backwards

Why it works Why are there no inconsistencies when we merge? B w q5 a A q2 q3 q1 q7 a C q6 Because we only merge indistinguishable states

Why it works Why is there no smaller DFA? Suppose there is By the pigeonhole principle this must happen: M q q’ v v’ smaller DFA M’ q” v, v’

Why it works Why is there no smaller DFA? But then M smaller DFA M’ v q w q” w ? v, v’ v’ q’ w Every pair of states is distinguishable q” cannot exist!