Presentation is loading. Please wait.

Presentation is loading. Please wait.

DFA Equivalence & Minimization

Similar presentations


Presentation on theme: "DFA Equivalence & Minimization"— Presentation transcript:

1 DFA Equivalence & Minimization
CS 350 — Fall 2018 gilray.org/classes/fall2018/cs350/

2 Models of regular languages
“Converts to” GNFA “Converts to” RE DFA “Minimizes to” NFA “Converts to” “Converts to”

3 For every regular language, there is a
unique minimum-state DFA which accepts it. (Modulo the names of states in Q.) Thus for any given DFA we can compute its minimal equivalent DFA.

4 The basic idea: we collapse/merge two states in the input DFA whenever those two states are equivalent (i.e., behave exactly the same for identical strings/string-suffixes).

5 The basic idea: we collapse/merge two states in the input DFA whenever those two states are equivalent (i.e., behave exactly the same for identical strings/string-suffixes). Two states. q0 and q1 are equivalent if for all strings s, q0 accepts on string s exactly when q1 accepts on string s: ∀𝑠∈ Σ ∗ .( 𝑞 0 ,𝑠, 𝑞 0 ′ ).∈ 𝛿 ̂ ∧ 𝑞 0 ′ ∈𝐹⟺( 𝑞 1 ,𝑠, 𝑞 1 ′ )∈ 𝛿 ̂ ∧ 𝑞 1 ′ ∈𝐹

6 Hopcroft Minimization: starts with a minimal partitioning of accept states from non-accept states (these states cannot be equivalent). Minimization proceeds by iteratively splitting partitions as necessary until the partitioning reaches a fixed point: then each partition represents one state in the minimal DFA (except any unreachable states/partitions)! J. Hopcroft. “An n log n algorithm for minimizing states in a finite automaton”

7 Splitting partitions: there is no need to split a partition (e. g
Splitting partitions: there is no need to split a partition (e.g. P1) if all its states transition (on any given input) to the same partition (e.g., P2). This is true even if they do not transition to the same exact state. P1 P2 q0 a q3 a q1 q4 a q2

8 Splitting partitions: We must split/refine a partition (e. g
Splitting partitions: We must split/refine a partition (e.g., P1 into P1 and P4) whenever a subset of its states (here q2) transition to states in a distinct partition (here q5) from those transitioned to (q3,q4 in P2) by other states in the partition (q0,q1). P1 P2 q0 a q3 q4 a q1 P3 b P4 a q5 q2

9 Hopcroft Minimization
Input: DFA (Q, Σ, δQ, q0, FQ) parts = {Q-FQ, FQ} work = {FQ} While ∃ p ∈ work: work -= p For each s ∈ Σ: Let preds = {q | (q,s,q’) ∈ δQ ∧ q’ ∈ p} For part∈parts: If part∩preds≠∅ ∧ part-preds≠∅: parts = parts-part ∪ {part∩preds,part-preds} If part ∈ work: work = work-part ∪ {part∩preds,part-preds} Else If |part∩preds| <= |part-preds|: work = work ∪ {part∩preds} Else: work = work ∪ {part-preds} Each partition is now a state in the minimal DFA!

10 Try an example: Minimize the following DFA.
q1 a c q0 b c q2 q3 dead 10

11 Try an example: Minimize the following DFA.
a,b c q0 q2 q3 dead 11

12 Try an example: Minimize the following DFA.
1 q1 q3 q0 1 1 q4 q2 dead 12

13 Try an example: Minimize the following DFA.
1 0,1 q2 q0 q1 dead 13


Download ppt "DFA Equivalence & Minimization"

Similar presentations


Ads by Google