DFA Minimiztion nd Applictions Mondy, Octoer 15, 2007 Reding: toughton 3.12 C235 Lnguges nd Automt Deprtment of Computer cience Wellesley College Gols for ody o Answer ny P3 questions you might hve. o ome informtion out hursdy s midterm. o DFA minimiztion o ome pplictions of regulr expressions nd utomt: Automt design using Forln Efficient tring erching Pttern Mtching with Regulr Expressions DFA Minimiztion 17-2 1
he Midterm o he midterm will e n in-clss exm during the lecture period on hu. Oct. 18. o It will cover mteril through tody s lecture (#17) nd prolem sets 1 3. o It is open ook/open notes. o Prolems will e esier thn most prolem set prolems. o tudy ll the prolem set solutions! o You re encourged to form study groups! o Where to find prctice prolems? toughton s course we site: Exercise ets nd Exms ipser Chpter 1 Exercises (not Prolems), some of which hve solutions DFA Minimiztion 17-3 Midterm Prolems you hould Prepre For o A simple proof y induction. o A simple proof y contrdiction/digonliztion. o Resoning out logic, sets, reltions, functions, ijections, nd closures (reflexive, symmetric, trnsitive). o Resoning out sizes nd continment of sets/lnguges. o Reding/writing simple ML functions, possily using the Forln functions you ve used in ssignments. o nderstnding the forml definition of FAs nd DFAs (i.e., qudruple of sttes, strt stte, ccepting stte, nd trnsitions). o implifying regulr expressions (only very simple simplifictions) o Converting etween English descriptions of lnguges, regulr expressions, FAs, EFAs, NFAs, DFAs. o Opertions involving products of DFAs: intersection, union, equivlence. DFA Minimiztion 17-4 2
Are nd Equivlent? K, M L R,, DFA Minimiztion 17-5 Are nd Equivlent? ke heir Product! K, M L R,, x ( K, ) ( R, L ) ( L, O ) ( M, ) (, ),, DFA Minimiztion 17-6 3
Miniml DFAs K, M L R,, A DFA is miniml if it hs the smllest numer of sttes of ny DFA ccepting its lnguge. Is miniml? Is miniml? DFA Minimiztion 17-7 tte Merging K, M L R,, A DFA is not miniml iff two sttes cn e merged to form single stte without chnging the mening of the DFA. Accepting sttes nd non-ccepting sttes cn never e merged. Which sttes in cn e merged? DFA Minimiztion 17-8 4
tte Merging in R Merge with R,,, (, ) Merge with {, }, R {, } DFA Minimiztion 17-9 ttes Cn t Alwys e Merged Itertively DFA 9 V X W Y imultneously merge V with X nd W with Y, Z { V, X } {W, Y }, Z DFA Minimiztion 17-10 5
DFA Minimiztion Algorithm: tep 1 List ll pirs of sttes thn must not e merged = pirs of one ccepting nd one non-ccepting stte. Other pirs might e mergele they re considered mergele until proven otherwise R,, nmergele (, R ), ( R, ), (, ), (, ), (, ), (, ), (, R ), ( R, ), (, ), (, ), (, ), (, ) Might-Be-Mergele (, ), ( R, R ), (, ), (, ), (, ), (, ), (, ), ( R, ), (, R ), ( R, ), (, R ), (, ), (, ) DFA Minimiztion 17-11 DFA Minimiztion Algorithm: tep 2 Move from Might-Be-Mergele to nmergele ny pir (A,B) such tht there is trnsition to (C,D) in nmergele: nmergele (, R ), ( R, ), (, ), (, ), (, ), (, ), (, R ), ( R, ), (, ), (, ), (, ), ( A, B ) (, ) ( C, D ) ( R, ), (, R ), ( R, ), (, R ), R, (, ), ( R, R ), (, ), (, R ), Might-Be-Mergele (, ), (, ), (, ), (, ), ( R, ), (, R ), ( R, ), (, ), (, ), DFA Minimiztion 17-12 6
DFA Minimiztion Algorithm: tep 3 Merge the non-trivil pirs remining int Might-Be-Mergele Might-Be-Mergele (, ), ( R, R ), (, ), (, ), (, ), (, ), (, ), (, ), (, ) R,, Merge with nd with {, } R {, }, DFA Minimiztion 17-13 DFA Minimiztion: More Prctice DFA 9 V X W Y, Z DFA Minimiztion 17-14 7
Designing DFAs with Forln sing Forln, design miniml DFA tht ccepts ny string of s nd s tht is one of the following: Any string eginning with two s. Any string ending in two s. Any string contining the sustring. Any string whose third-to-lst chrcter is. DFA Minimiztion 17-15 8