Regulr lnguges refresher 1
Regulr lnguges refresher Forml lnguges Alphet = finite set of letters Word = sequene of letter Lnguge = set of words Regulr lnguges defined equivlently y Regulr expressions Finite-stte utomt 2
Regulr expressions Empty string: Є Letter: Contention: R 1 R 2 Union: R 1 R 2 Kleene-str: R* Shorthnd: R + stnds for R R* sope: (R) Exmple: (0* 1*) (1* 0*) Wht is this lnguge? 3
Finite utomt 4
Finite utomt: known results Types of finite utomt: Deterministi (DFA) Non-deterministi (NFA) Non-deterministi + epsilon trnsitions Theorem: trnsltion of regulr expressions to NFA+epsilon (liner time) Theorem: trnsltion of NFA+epsilon to DFA Worst-se exponentil time Theorem [Myhill-Nerode]: DFA n e minimized 5
Finite utomt An utomton M = Q,,, q 0, F is defined y sttes nd trnsitions trnsition epting stte strt strt stte 6
Automton running exmple Words re red left-to-right strt 7
Automton running exmple Words re red left-to-right strt 8
Automton running exmple Words re red left-to-right strt 9
Automton running exmple Words re red left-to-right word epted strt 10
Word outside of lnguge 1 strt 11
Word outside of lnguge 1 Missing trnsition mens non-eptne strt 12
Word outside of lnguge 2 strt 13
Word outside of lnguge 2 strt 14
Word outside of lnguge 2 Finl stte is not n epting stte strt 15
Exerise - Question Wht is the lnguge defined y the utomton elow? strt 16
Exerise - Answer Wht is the lnguge defined y the utomton elow *? Generlly: ll pths leding to epting sttes strt 17
Nondeterministi Finite utomt 18
Non-deterministi utomt Allow multiple trnsitions from given stte leled y sme letter strt 19
NFA run exmple strt 20
Mintin set of sttes NFA run exmple strt 21
NFA run exmple strt 22
NFA run exmple Aept word if ny of the sttes in the set is epting strt 23
NFA+Є utomt Є trnsitions n fire without reding the input strt Є 24
NFA+Є run exmple strt Є 25
NFA+Є run exmple Now Є trnsition n non-deterministilly tke ple strt Є 26
NFA+Є run exmple strt Є 27
NFA+Є run exmple strt Є 28
NFA+Є run exmple strt Є 29
Word epted NFA+Є run exmple strt Є 30
From Regulr expressions to NFA 31
From reg. exp. to utomt Theorem: there is n lgorithm to uild n NFA+Є utomton for ny regulr expression Proof: y indution on the struture of the regulr expression For eh su-expression R we uild n utomton with extly one strt stte nd one epting stte Strt stte hs no inoming trnsitions Aepting stte hs no outgoing trnsitions 32
From reg. exp. to NFA+Є utomt Theorem: there is n lgorithm to uild n NFA+Є utomton for ny regulr expression Proof: y indution on the struture of the regulr expression strt 33
Indutive onstrutions R = strt R 1 R 2 R 1 R = strt strt R 2 R * strt R R 1 R 2 strt R 1 R 2 34
Running time of NFA+Є Constrution requires O(k) sttes for reg-exp of length k Running n NFA+Є with k sttes on string of length n tkes O(n k 2 ) time Cn we redue the k 2 ftor? Eh stte in onfigurtion of O(k) sttes my hve O(k) outgoing edges, so proessing n input letter my tke O(n 2 ) time 35
From NFA+Є to DFA Constrution requires O(k) sttes for reg-exp of length k Running n NFA+Є with k sttes on string of length n tkes O(n k 2 ) time Cn we redue the k 2 ftor? Theorem: for ny NFA+Є utomton there exists n equivlent deterministi utomton Proof: determiniztion vi suset onstrution Numer of sttes in the worst-se O(2 k ) Running time O(n) 36
NFA determiniztion 37
Suset onstrution For n NFA+Є with sttes M={s 1,,s k } Construt DFA with one stte per set of sttes of the orresponding NFA M ={ [], [s 1 ], [s 1,s 2 ], [s 2,s 3 ], [s 1,s 2,s 3 ], } Simulte trnsitions etween individul sttes for every letter NFA+Є s s 1 2 s s 4 7 DFA [s 1,s 4 ] [s 2,s 7 ] 38
Hndling epsilon trnsitions Extend mro sttes y sttes rehle vi Є trnsitions NFA+Є DFA s Є s 1 4 [s 1,s 2 ] [s 1,s 2,s 4 ] 39