Where did dynamic programming come from?
|
|
- Brent Richards
- 6 years ago
- Views:
Transcription
1 Where did dynmic progrmming come from? String lgorithms Dvid Kuchk cs302 Spring 2012 Richrd ellmn On the irth of Dynmic Progrmming Sturt Dreyfus or50/ pdf Strings l Let Σ be n lphbet, e.g. Σ = (,, b, c,, z) l string is ny member of Σ*, i.e. ny sequence of 0 or more members of Σ l this is string Σ* l this is lso string Σ* l 1234 Σ* String opertions l Given strings s 1 of length n nd s 2 of length m l Equlity: is s 1 = s 2? (cse sensitive or insensitive) this is string = this is string this is string this is nother string this is string =? THIS IS STRING l Running time l O(n) where n is length of shortest string 1
2 String opertions l Conctente (ppend): crete string s 1 s 2 this is. string this is string l Running time (ssuming we generte new string) l Θ(n+m) String opertions l Substitute: Exchnge ll occurrences of prticulr chrcter with nother chrcter l Running time l Θ(n) Substitute( this is string, i, x ) thxs xs strxng Substitute( bnn,, o ) bonono String opertions l Length: return the number of chrcters/ symbols in the string Length( this is string ) 16 Length( this is nother string ) 24 l Running time l O(1) or Θ(n) depending on implementtion String opertions l Prefix: Get the first j chrcters in the string Prefix( this is string, 4) this l Running time l Θ(j) l Suffix: Get the lst j chrcters in the string Suffix( this is string, 6) string l Running time l Θ(j) 2
3 String opertions l Substring Get the chrcters between i nd j inclusive Substring( this is string, 4, 8) s is Edit distnce (k Levenshtein distnce) Edit distnce between two strings is the minimum number of insertions, deletions nd substitutions required to trnsform string s 1 into string s 2 l Running time l Θ(j i + 1) l Prefix: Prefix(S, i) = Substring(S, 1, i) l Suffix: Suffix(S, i) = Substring(S, i+1, length(n)) Insertion: CED CCED DCCED Insert C Insert D Edit distnce (k Levenshtein distnce) Edit distnce between two strings is the minimum number of insertions, deletions nd substitutions required to trnsform string s 1 into string s 2 Edit distnce (k Levenshtein distnce) Edit distnce between two strings is the minimum number of insertions, deletions nd substitutions required to trnsform string s 1 into string s 2 Deletion: Deletion: CED CED CED Delete 3
4 Edit distnce (k Levenshtein distnce) Edit distnce between two strings is the minimum number of insertions, deletions nd substitutions required to trnsform string s 1 into string s 2 Edit distnce (k Levenshtein distnce) Edit distnce between two strings is the minimum number of insertions, deletions nd substitutions required to trnsform string s 1 into string s 2 Deletion: CED CED CE Substitution: CED DED DES Delete Delete D Sub D for C Sub S for D Edit distnce exmples Edit distnce exmples Edit(Kitten, Mitten) = 1 Edit(Hppy, Hilly) = 3 Opertions: Opertions: Sub M for K Mitten Sub for i Hippy Sub l for p Hilpy Sub l for p Hilly 4
5 Edit distnce exmples Edit distnce exmples Edit(nn, Cr) = 5 Edit(Simple, pple) = 3 Opertions: Opertions: Delete nn Delete S imple Delete nn Sub for i mple Delete n n Sub m for p pple Sub C for n C Sub for r Cr Edit distnce Is edit distnce symmetric? l tht is, is Edit(s 1, s 2 ) = Edit(s 2, s 1 )? Edit(Simple, pple) =? Edit(pple, Simple) Why might this be useful? l Why? l sub i for j sub j for i l delete i insert i l insert i delete i 5
6 Clculting edit distnce X = C D Y = D C Clculting edit distnce X = C D? Y = D C? Ides? fter ll of the opertions, X needs to equl Y Clculting edit distnce X = C D? Y = D C? Insert X = C D? Y = D C? Opertions: Insert Delete Substitute 6
7 Insert X = C D? Edit Y = D C? Delete X = C D? Y = D C? Edit ( X, Y ) = 1+ Edit ( X 1... n, Y 1... m 1) Delete X = C D? Edit Y = D C? Substition X = C D? Y = D C? Edit ( X, Y) = 1+ Edit ( X... n 1, Y m ) 7
8 Substition X = C D? Edit Y = D C? nything else? X = C D? Y = D C? Edit ( X, Y) = 1+ Edit ( X1... n 1, Y1... m 1) Equl X = C D? Y = D C? Equl X = C D? Edit Y = D C? Edit( X, Y) = Edit( X1... n 1, Y1... m 1) 8
9 Combining results Combining results Insert: Delete: Edit ( X, Y ) = 1+ Edit ( X 1... n, Y 1... m 1) Edit ( X, Y) = 1+ Edit ( X... n 1, Y m ) 1+ Edit(X 1...n,Y1... m 1) Edit ( X, Y) = min 1+ Edit ( X1... n 1, Y1... m) Diff ( xn, ym) + Edit ( X1... n 1, Y 1... m 1 ) insertion deletion equl/substitution Substitute: Edit ( X, Y) = 1+ Edit ( X1... n 1, Y1... m 1) Equl: Edit( X, Y) = Edit( X1... n 1, Y1... m 1) Running time Vrints l Only include insertions nd deletions l Wht does this do to substitutions? Θ(nm) l Include swps, i.e. swpping two djcent chrcters counts s one edit l Weight insertion, deletion nd substitution differently l Weight specific chrcter insertion, deletion nd substitutions differently l Length normlize the edit distnce 9
10 String mtching Given pttern string P of length m nd string S of length n, find ll loctions where P occurs in S String mtching Given pttern string P of length m nd string S of length n, find ll loctions where P occurs in S P = S = DC P = S = DC Uses Nive implementtion l grep/egrep l serch l find l jv.lng.string.contins() 10
11 Is it correct? Running time? l Wht is the cost of the equlity check? l est cse: O(1) l Worst cse: O(m) Running time? Worst cse P = S = l est cse l Θ(n) when the first chrcter of the pttern does not occur in the string l Worst cse l O((n-m+1)m) 11
12 Worst cse P = S = Worst cse P = S = Worst cse P = S = Worst cse P = S = repeted work! Idelly, fter the first mtch, we d know to just check the next chrcter to see if it is n 12
13 Ptterns Which of these ptterns will hve tht problem? Ptterns Which of these ptterns will hve tht problem? P = P = DC P = P = CDDC P = P = DC P = P = CDDC If the pttern hs suffix tht is lso prefix then we will hve this problem Finite Stte utomt (FS) l n FS is defined by 5 components l Q is the set of sttes q 0 q 1 q 2 q n Finite Stte utomt (FS) l n FS is defined by 5 components l Q is the set of sttes q 0 q 1 q 2 q n l q 0 is the strt stte l Q, is the set of ccepting sttes where > 0 l Σ is the lphbet (e.g. {, } l δ is the trnsition function from Q x Σ to Q Q Σ Q q 0 q 1 q 0 q 2 q 1 q 1 q 0 q 1 q 2 q 7 13
14 FS opertion FS opertion P = q 0 q 1 q q 2 3 q 0 q 1 q q 2 3 n FS strts t stte q 0 nd reds the chrcters of the input string one t time. If the utomton is in stte q nd reds chrcter, then it trnsitions to stte δ(q,). If the FS reches n ccepting stte (q ), then the FS hs found mtch. Wht pttern does this represent? FS opertion FS opertion P = P = q 0 q 1 q q 2 3 q 0 q 1 q q 2 3 S = S = 14
15 FS opertion FS opertion P = P = q 0 q 1 q q 2 3 q 0 q 1 q q 2 3 S = S = FS opertion FS opertion P = P = q 0 q 1 q q 2 3 q 0 q 1 q q 2 3 S = S = 15
16 FS opertion FS opertion P = P = q 0 q 1 q q 2 3 q 0 q 1 q q 2 3 S = S = FS opertion FS opertion P = P = q 0 q 1 q q 2 3 q 0 q 1 q q 2 3 S = S = 16
17 FS opertion FS opertion P = P = q 0 q 1 q q 2 3 q 0 q 1 q q 2 3 S = S = Suffix function l The suffix function σ(x,y) is the length of the longest suffix of x tht is prefix of y σ( x, y) = mx( xm i m = y1... i) i σ(bcdb, bbcd) =? Suffix function l The suffix function σ(x,y) is the length of the longest suffix of x tht is prefix of y σ( x, y) = mx( xm i m = y1... i) i σ(bcdb, bbcd) = 2 17
18 Suffix function l The suffix function σ(x,y) is the index of the longest suffix of x tht is prefix of y σ( x, y) = mx( xm i m = y1... i) i σ(dbc, bcc) =? Suffix function l The suffix function σ(x,y) is the length of the longest suffix of x tht is prefix of y σ( x, y) = mx( xm i m = y1... i) i σ(dbc, bcc) = 4 Suffix function l The suffix function σ(x,y) is the length of the longest suffix of x tht is prefix of y σ( x, y) = mx( xm i m = y1... i) σ(dbb, bcd) =? i Suffix function l The suffix function σ(x,y) is the length of the longest suffix of x tht is prefix of y σ( x, y) = mx( xm i m = y1... i) σ(dbb, bcd) = 0 i 18
19 uilding string mtching utomt l Given pttern P = p 1, p 2,, p m, we d like to build n FS tht recognizes P in strings P = bbc Ides? uilding string mtching utomt P = bbc l Q = q 1, q 2,, q m corresponding to ech symbol, plus q 0 strting stte l the set of ccepting sttes, = {q m } l vocb Σ ll symbols in P, plus one more representing ll symbols not in P l The trnsition function for q Q nd Σ is defined s: l δ(q, ) = σ(p 1 q, P) Trnsition function P = bbc l δ(q, ) = σ(p 1 q, P) Trnsition function P = bbc l δ(q, ) = σ(p 1 q, P) stte b c P q 0? q 1 q 2 q 3 q 4 q 5 q 6 b b c σ(, bbc) stte b c P q 0 1? q 1 q 2 q 3 q 4 q 5 q 6 b b c σ(b, bbc) q 7 q 7 19
20 Trnsition function P = bbc l δ(q, ) = σ(p 1 q, P) Trnsition function P = bbc l δ(q, ) = σ(p 1 q, P) stte b c P q 0 1 0? q 1 q 2 q 3 q 4 q 5 q 6 b b c σ(b, bbc) stte b c P q q 1 q 2 q 3 q 4 q 5 q 6 b b c σ(b, bbc) q 7 q 7 Trnsition function P = bbc l δ(q, ) = σ(p 1 q, P) stte b c P q q 1 q 2 q 3 q 4 q 5 q 6 q 7 b b c,c q 0 q 1 Trnsition function P = bbc l δ(q, ) = σ(p 1 q, P) stte b c P q q b q q 3? b q 4 q 5 q 6 q 7 c We ve seen b so fr σ(b, bbc) 20
21 Trnsition function P = bbc l δ(q, ) = σ(p 1 q, P) Trnsition function P = bbc l δ(q, ) = σ(p 1 q, P) stte b c P q q b q q 3 1 b q 4 q 5 q 6 c We ve seen b so fr σ(b, bbc) stte b c P q q b q q b q q 5 1? c q 6 We ve seen bb so fr q 7 q 7 Trnsition function P = bbc l δ(q, ) = σ(p 1 q, P) Trnsition function P = bbc l δ(q, ) = σ(p 1 q, P) stte b c P q q b q q b q q 5 1? c q 6 We ve seen bb so fr σ(bbb, bbc) stte b c P q q b q q b q q c q 6 We ve seen bb so fr σ(bbb, bbc) q 7 q 7 21
22 Trnsition function P = bbc l δ(q, ) = σ(p 1 q, P) stte b c P q q b q q b q q c q q Mtching runtime l Once we ve built the FS, wht is the runtime? l Θ(n) - Ech symbol cuses stte trnsition nd we only visit ech chrcter once l Wht is the cost to build the FS? l How mny entries in the tble? l Ω(m Σ ) l How long does it tke to clculte the suffix function t ech entry? l Nïve: O(m) l Overll nïve: O(m 2 Σ ) l Overll fst implementtion O(m Σ ) Rbin-Krp lgorithm - Use function T to tht computes numericl representtion of P - Clculte T for ll m symbol sequences of S nd compre Rbin-Krp lgorithm - Use function T to tht computes numericl representtion of P - Clculte T for ll m symbol sequences of S nd compre P = P = Hsh P T(P) S = S = 22
23 Rbin-Krp lgorithm - Use function T to tht computes numericl representtion of P - Clculte T for ll m symbol sequences of S nd compre P = Rbin-Krp lgorithm - Use function T to tht computes numericl representtion of P - Clculte T for ll m symbol sequences of S nd compre P = S = Hsh m symbol sequences nd compre mtch S = Hsh m symbol sequences nd compre T() = T(P) T() = T(P) Rbin-Krp lgorithm - Use function T to tht computes numericl representtion of P - Clculte T for ll m symbol sequences of S nd compre P = Rbin-Krp lgorithm - Use function T to tht computes numericl representtion of P - Clculte T for ll m symbol sequences of S nd compre P = S = T() = T(P) Hsh m symbol sequences nd compre S = T() = T(P) Hsh m symbol sequences nd compre 23
24 Rbin-Krp lgorithm Rbin-Krp lgorithm P = For this to be useful/ efficient, wht needs to be true bout T? P = For this to be useful/ efficient, wht needs to be true bout T? S = T() = T(P) S = T() = T(P) Given T(s i i+m-1 ) we must be ble to efficiently clculte T(s i+1 i+m ) Clculting the hsh function l For simplicity, ssume Σ = (0, 1, 2,, 9). (in generl we cn use bse lrger thn 10). l string cn then be viewed s deciml number l How do we efficiently clculte the numericl representtion of string? T( ) =? Horner s rule T( p1... m ) = pm + 10( pm ( pm ( p p1))) * 10 = 90 (90 + 8)*10 = 980 ( )*10 = 9840 ( )*10 = =
25 Horner s rule T( p1... m ) = pm + 10( pm ( pm ( p p1))) Running time? 9 * 10 = 90 (90 + 8)*10 = 980 ( )*10 = 9840 ( )*10 = = Θ(m) Clculting the hsh on the string l Given T(s i i+m-1 ) how cn we efficiently clculte T(s i+1 i+m )? m = T(s i i+m-1 ) m 1 T ( si i+ m) = 10( T ( si... i+ m 1) 10 si ) + si+ m Clculting the hsh on the string l Given T(s i i+m-1 ) how cn we efficiently clculte T(s i+1 i+m )? Clculting the hsh on the string l Given T(s i i+m-1 ) how cn we efficiently clculte T(s i+1 i+m )? m = m = T(s i i+m-1 ) subtrct highest order digit T(s i i+m-1 ) shift digits up m 1 T ( si i+ m) = 10( T ( si... i+ m 1) 10 si ) + si+ m m 1 T ( si i+ m) = 10( T ( si... i+ m 1) 10 si ) + si+ m 25
26 Clculting the hsh on the string l Given T(s i i+m-1 ) how cn we efficiently clculte T(s i+1 i+m )? Clculting the hsh on the string l Given T(s i i+m-1 ) how cn we efficiently clculte T(s i+1 i+m )? m = m = Running time? - Θ(m) for s 1 m - O(1) for the rest T(s i i+m-1 ) dd in the lowest digit T(s i i+m-1 ) m 1 T ( si i+ m) = 10( T ( si... i+ m 1) 10 si ) + si+ m m 1 T ( si i+ m) = 10( T ( si... i+ m 1) 10 si ) + si+ m lgorithm so fr l Is it correct? l Ech string hs unique numericl vlue nd we compre tht with ech vlue in the string l Running time l Preprocessing: l Θ(m) l Mtching l Θ(n-m+1) Is there ny problem with this nlysis? lgorithm so fr l Is it correct? l Ech string hs unique numericl vlue nd we compre tht with ech vlue in the string l Running time l Preprocessing: l Θ(m) l Mtching l Θ(n-m+1) How long does the check T(P) = T(s i i+m-1 ) tke? 26
27 Modulr rithmetics l The run time ssumptions we mde were ssuming rithmetic opertions were constnt time, which is not true for lrge numbers l To keep the numbers smll, we ll use modulr rithmetics, i.e. ll opertions re performed mod q l +b = (+b) mod q l *b = (*b) mod q l Modulr rithmetics l If T() = T(), then T() mod q = T() mod q l In generl, we cn pply mods s mny times s we wnt nd we will not effect the result l Wht is the downside to this modulr pproch? l Spurious hits: if T() mod q = T() mod q tht does not necessrily men tht T() = T() l If we find hit, we must check tht the ctul string mtches the pttern Runtime l Preprocessing l Θ(m) l Running time l est cse: l Θ(n-m+1) No mtches nd no spurious hits l Worst cse l Θ((n-m+1)m) verge cse running time l ssume v vlid mtches in the string l Wht is the probbility of spurious hit? l s with hshing, ssume uniform mpping onto vlues of q: Σ* 1 q l Wht is the probbility under this ssumption? 27
28 verge cse running time l ssume v vlid mtches in the string l Wht is the probbility of spurious hit? l s with hshing, ssume uniform mpping onto vlues of q: verge cse running time l How mny spurious hits? l n/q l verge cse running time: O(n-m+1) + O(m(v+n/q)) Σ* 1 q iterte over the positions checking mtches nd spurious hits l Wht is the probbility under this ssumption? 1/q Mtching running times lgorithm Preprocessing time Mtching time Nïve 0 O((n-m+1)m) FS Θ(m Σ ) Θ(n) Rbin-Krp Θ(m) O(n)+O(m(v+n/q)) Knuth-Morris-Prtt Θ(m) Θ(n) 28
Module 9: Tries and String Matching
Module 9: Tries nd String Mtching CS 240 - Dt Structures nd Dt Mngement Sjed Hque Veronik Irvine Tylor Smith Bsed on lecture notes by mny previous cs240 instructors Dvid R. Cheriton School of Computer
More informationModule 9: Tries and String Matching
Module 9: Tries nd String Mtching CS 240 - Dt Structures nd Dt Mngement Sjed Hque Veronik Irvine Tylor Smith Bsed on lecture notes by mny previous cs240 instructors Dvid R. Cheriton School of Computer
More informationFingerprint idea. Assume:
Fingerprint ide Assume: We cn compute fingerprint f(p) of P in O(m) time. If f(p) f(t[s.. s+m 1]), then P T[s.. s+m 1] We cn compre fingerprints in O(1) We cn compute f = f(t[s+1.. s+m]) from f(t[s.. s+m
More informationAnatomy of a Deterministic Finite Automaton. Deterministic Finite Automata. A machine so simple that you can understand it in less than one minute
Victor Admchik Dnny Sletor Gret Theoreticl Ides In Computer Science CS 5-25 Spring 2 Lecture 2 Mr 3, 2 Crnegie Mellon University Deterministic Finite Automt Finite Automt A mchine so simple tht you cn
More informationBalanced binary search trees
02110 Inge Li Gørtz Overview Blnced binry serch trees: Red-blck trees nd 2-3-4 trees Amortized nlysis Dynmic progrmming Network flows String mtching String indexing Computtionl geometry Introduction to
More informationCMSC 330: Organization of Programming Languages. DFAs, and NFAs, and Regexps (Oh my!)
CMSC 330: Orgniztion of Progrmming Lnguges DFAs, nd NFAs, nd Regexps (Oh my!) CMSC330 Spring 2018 Types of Finite Automt Deterministic Finite Automt (DFA) Exctly one sequence of steps for ech string All
More informationData Structures and Algorithm. Xiaoqing Zheng
Dt Strutures nd Algorithm Xioqing Zheng zhengxq@fudn.edu.n String mthing prolem Pttern P ours with shift s in text T (or, equivlently, tht pttern P ours eginning t position s + in text T) if T[s +... s
More informationCMSC 330: Organization of Programming Languages
CMSC 330: Orgniztion of Progrmming Lnguges Finite Automt 2 CMSC 330 1 Types of Finite Automt Deterministic Finite Automt (DFA) Exctly one sequence of steps for ech string All exmples so fr Nondeterministic
More informationNFAs and Regular Expressions. NFA-ε, continued. Recall. Last class: Today: Fun:
CMPU 240 Lnguge Theory nd Computtion Spring 2019 NFAs nd Regulr Expressions Lst clss: Introduced nondeterministic finite utomt with -trnsitions Tody: Prove n NFA- is no more powerful thn n NFA Introduce
More informationTypes of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. NFA for (a b)*abb.
CMSC 330: Orgniztion of Progrmming Lnguges Finite Automt 2 Types of Finite Automt Deterministic Finite Automt () Exctly one sequence of steps for ech string All exmples so fr Nondeterministic Finite Automt
More informationTypes of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. Comparing DFAs and NFAs (cont.) Finite Automata 2
CMSC 330: Orgniztion of Progrmming Lnguges Finite Automt 2 Types of Finite Automt Deterministic Finite Automt () Exctly one sequence of steps for ech string All exmples so fr Nondeterministic Finite Automt
More information1.4 Nonregular Languages
74 1.4 Nonregulr Lnguges The number of forml lnguges over ny lphbet (= decision/recognition problems) is uncountble On the other hnd, the number of regulr expressions (= strings) is countble Hence, ll
More informationCS 373, Spring Solutions to Mock midterm 1 (Based on first midterm in CS 273, Fall 2008.)
CS 373, Spring 29. Solutions to Mock midterm (sed on first midterm in CS 273, Fll 28.) Prolem : Short nswer (8 points) The nswers to these prolems should e short nd not complicted. () If n NF M ccepts
More informationNFA DFA Example 3 CMSC 330: Organization of Programming Languages. Equivalence of DFAs and NFAs. Equivalence of DFAs and NFAs (cont.
NFA DFA Exmple 3 CMSC 330: Orgniztion of Progrmming Lnguges NFA {B,D,E {A,E {C,D {E Finite Automt, con't. R = { {A,E, {B,D,E, {C,D, {E 2 Equivlence of DFAs nd NFAs Any string from {A to either {D or {CD
More informationFormal languages, automata, and theory of computation
Mälrdlen University TEN1 DVA337 2015 School of Innovtion, Design nd Engineering Forml lnguges, utomt, nd theory of computtion Thursdy, Novemer 5, 14:10-18:30 Techer: Dniel Hedin, phone 021-107052 The exm
More informationConvert the NFA into DFA
Convert the NF into F For ech NF we cn find F ccepting the sme lnguge. The numer of sttes of the F could e exponentil in the numer of sttes of the NF, ut in prctice this worst cse occurs rrely. lgorithm:
More information11.1 Finite Automata. CS125 Lecture 11 Fall Motivation: TMs without a tape: maybe we can at least fully understand such a simple model?
CS125 Lecture 11 Fll 2016 11.1 Finite Automt Motivtion: TMs without tpe: mybe we cn t lest fully understnd such simple model? Algorithms (e.g. string mtching) Computing with very limited memory Forml verifiction
More informationSOLUTIONS FOR ADMISSIONS TEST IN MATHEMATICS, COMPUTER SCIENCE AND JOINT SCHOOLS WEDNESDAY 5 NOVEMBER 2014
SOLUTIONS FOR ADMISSIONS TEST IN MATHEMATICS, COMPUTER SCIENCE AND JOINT SCHOOLS WEDNESDAY 5 NOVEMBER 014 Mrk Scheme: Ech prt of Question 1 is worth four mrks which re wrded solely for the correct nswer.
More informationAlignment of Long Sequences. BMI/CS Spring 2016 Anthony Gitter
Alignment of Long Sequences BMI/CS 776 www.biostt.wisc.edu/bmi776/ Spring 2016 Anthony Gitter gitter@biostt.wisc.edu Gols for Lecture Key concepts how lrge-scle lignment differs from the simple cse the
More informationCS:4330 Theory of Computation Spring Regular Languages. Equivalences between Finite automata and REs. Haniel Barbosa
CS:4330 Theory of Computtion Spring 208 Regulr Lnguges Equivlences between Finite utomt nd REs Hniel Brbos Redings for this lecture Chpter of [Sipser 996], 3rd edition. Section.3. Finite utomt nd regulr
More informationIntermediate Math Circles Wednesday, November 14, 2018 Finite Automata II. Nickolas Rollick a b b. a b 4
Intermedite Mth Circles Wednesdy, Novemer 14, 2018 Finite Automt II Nickols Rollick nrollick@uwterloo.c Regulr Lnguges Lst time, we were introduced to the ide of DFA (deterministic finite utomton), one
More informationFirst Midterm Examination
Çnky University Deprtment of Computer Engineering 203-204 Fll Semester First Midterm Exmintion ) Design DFA for ll strings over the lphet Σ = {,, c} in which there is no, no nd no cc. 2) Wht lnguge does
More informationTheory of Computation Regular Languages
Theory of Computtion Regulr Lnguges Bow-Yw Wng Acdemi Sinic Spring 2012 Bow-Yw Wng (Acdemi Sinic) Regulr Lnguges Spring 2012 1 / 38 Schemtic of Finite Automt control 0 0 1 0 1 1 1 0 Figure: Schemtic of
More informationTheory of Computation Regular Languages. (NTU EE) Regular Languages Fall / 38
Theory of Computtion Regulr Lnguges (NTU EE) Regulr Lnguges Fll 2017 1 / 38 Schemtic of Finite Automt control 0 0 1 0 1 1 1 0 Figure: Schemtic of Finite Automt A finite utomton hs finite set of control
More information1.3 Regular Expressions
56 1.3 Regulr xpressions These hve n importnt role in describing ptterns in serching for strings in mny pplictions (e.g. wk, grep, Perl,...) All regulr expressions of lphbet re 1.Ønd re regulr expressions,
More informationNFAs continued, Closure Properties of Regular Languages
Algorithms & Models of Computtion CS/ECE 374, Fll 2017 NFAs continued, Closure Properties of Regulr Lnguges Lecture 5 Tuesdy, Septemer 12, 2017 Sriel Hr-Peled (UIUC) CS374 1 Fll 2017 1 / 31 Regulr Lnguges,
More informationFaster Regular Expression Matching. Philip Bille Mikkel Thorup
Fster Regulr Expression Mtching Philip Bille Mikkel Thorup Outline Definition Applictions History tour of regulr expression mtching Thompson s lgorithm Myers lgorithm New lgorithm Results nd extensions
More information1 Nondeterministic Finite Automata
1 Nondeterministic Finite Automt Suppose in life, whenever you hd choice, you could try oth possiilities nd live your life. At the end, you would go ck nd choose the one tht worked out the est. Then you
More informationChapter 2 Finite Automata
Chpter 2 Finite Automt 28 2.1 Introduction Finite utomt: first model of the notion of effective procedure. (They lso hve mny other pplictions). The concept of finite utomton cn e derived y exmining wht
More informationLecture 09: Myhill-Nerode Theorem
CS 373: Theory of Computtion Mdhusudn Prthsrthy Lecture 09: Myhill-Nerode Theorem 16 Ferury 2010 In this lecture, we will see tht every lnguge hs unique miniml DFA We will see this fct from two perspectives
More informationNFAs continued, Closure Properties of Regular Languages
lgorithms & Models of omputtion S/EE 374, Spring 209 NFs continued, losure Properties of Regulr Lnguges Lecture 5 Tuesdy, Jnury 29, 209 Regulr Lnguges, DFs, NFs Lnguges ccepted y DFs, NFs, nd regulr expressions
More informationFinite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018
Finite Automt Theory nd Forml Lnguges TMV027/DIT321 LP4 2018 Lecture 10 An Bove April 23rd 2018 Recp: Regulr Lnguges We cn convert between FA nd RE; Hence both FA nd RE ccept/generte regulr lnguges; More
More informationCS 188: Artificial Intelligence Spring 2007
CS 188: Artificil Intelligence Spring 2007 Lecture 3: Queue-Bsed Serch 1/23/2007 Srini Nrynn UC Berkeley Mny slides over the course dpted from Dn Klein, Sturt Russell or Andrew Moore Announcements Assignment
More informationHomework 3 Solutions
CS 341: Foundtions of Computer Science II Prof. Mrvin Nkym Homework 3 Solutions 1. Give NFAs with the specified numer of sttes recognizing ech of the following lnguges. In ll cses, the lphet is Σ = {,1}.
More information1 Structural induction, finite automata, regular expressions
Discrete Structures Prelim 2 smple uestions s CS2800 Questions selected for spring 2017 1 Structurl induction, finite utomt, regulr expressions 1. We define set S of functions from Z to Z inductively s
More information19 Optimal behavior: Game theory
Intro. to Artificil Intelligence: Dle Schuurmns, Relu Ptrscu 1 19 Optiml behvior: Gme theory Adversril stte dynmics hve to ccount for worst cse Compute policy π : S A tht mximizes minimum rewrd Let S (,
More informationFor convenience, we rewrite m2 s m2 = m m m ; where m is repeted m times. Since xyz = m m m nd jxyj»m, we hve tht the string y is substring of the fir
CSCI 2400 Models of Computtion, Section 3 Solutions to Homework 4 Problem 1. ll the solutions below refer to the Pumping Lemm of Theorem 4.8, pge 119. () L = f n b l k : k n + lg Let's ssume for contrdiction
More informationLexical Analysis Finite Automate
Lexicl Anlysis Finite Automte CMPSC 470 Lecture 04 Topics: Deterministic Finite Automt (DFA) Nondeterministic Finite Automt (NFA) Regulr Expression NFA DFA A. Finite Automt (FA) FA re grph, like trnsition
More informationFinite Automata. Informatics 2A: Lecture 3. Mary Cryan. 21 September School of Informatics University of Edinburgh
Finite Automt Informtics 2A: Lecture 3 Mry Cryn School of Informtics University of Edinburgh mcryn@inf.ed.c.uk 21 September 2018 1 / 30 Lnguges nd Automt Wht is lnguge? Finite utomt: recp Some forml definitions
More informationMinimal DFA. minimal DFA for L starting from any other
Miniml DFA Among the mny DFAs ccepting the sme regulr lnguge L, there is exctly one (up to renming of sttes) which hs the smllest possile numer of sttes. Moreover, it is possile to otin tht miniml DFA
More informationFirst Midterm Examination
24-25 Fll Semester First Midterm Exmintion ) Give the stte digrm of DFA tht recognizes the lnguge A over lphet Σ = {, } where A = {w w contins or } 2) The following DFA recognizes the lnguge B over lphet
More information3 Regular expressions
3 Regulr expressions Given n lphet Σ lnguge is set of words L Σ. So fr we were le to descrie lnguges either y using set theory (i.e. enumertion or comprehension) or y n utomton. In this section we shll
More informationFinite Automata. Informatics 2A: Lecture 3. John Longley. 22 September School of Informatics University of Edinburgh
Lnguges nd Automt Finite Automt Informtics 2A: Lecture 3 John Longley School of Informtics University of Edinburgh jrl@inf.ed.c.uk 22 September 2017 1 / 30 Lnguges nd Automt 1 Lnguges nd Automt Wht is
More informationCS375: Logic and Theory of Computing
CS375: Logic nd Theory of Computing Fuhu (Frnk) Cheng Deprtment of Computer Science University of Kentucky 1 Tble of Contents: Week 1: Preliminries (set lgebr, reltions, functions) (red Chpters 1-4) Weeks
More information1 Probability Density Functions
Lis Yn CS 9 Continuous Distributions Lecture Notes #9 July 6, 28 Bsed on chpter by Chris Piech So fr, ll rndom vribles we hve seen hve been discrete. In ll the cses we hve seen in CS 9, this ment tht our
More informationClosure Properties of Regular Languages
Closure Properties of Regulr Lnguges Regulr lnguges re closed under mny set opertions. Let L 1 nd L 2 e regulr lnguges. (1) L 1 L 2 (the union) is regulr. (2) L 1 L 2 (the conctention) is regulr. (3) L
More informationChapter Five: Nondeterministic Finite Automata. Formal Language, chapter 5, slide 1
Chpter Five: Nondeterministic Finite Automt Forml Lnguge, chpter 5, slide 1 1 A DFA hs exctly one trnsition from every stte on every symol in the lphet. By relxing this requirement we get relted ut more
More informationMore on automata. Michael George. March 24 April 7, 2014
More on utomt Michel George Mrch 24 April 7, 2014 1 Automt constructions Now tht we hve forml model of mchine, it is useful to mke some generl constructions. 1.1 DFA Union / Product construction Suppose
More informationp-adic Egyptian Fractions
p-adic Egyptin Frctions Contents 1 Introduction 1 2 Trditionl Egyptin Frctions nd Greedy Algorithm 2 3 Set-up 3 4 p-greedy Algorithm 5 5 p-egyptin Trditionl 10 6 Conclusion 1 Introduction An Egyptin frction
More informationLet's start with an example:
Finite Automt Let's strt with n exmple: Here you see leled circles tht re sttes, nd leled rrows tht re trnsitions. One of the sttes is mrked "strt". One of the sttes hs doule circle; this is terminl stte
More informationState Minimization for DFAs
Stte Minimiztion for DFAs Red K & S 2.7 Do Homework 10. Consider: Stte Minimiztion 4 5 Is this miniml mchine? Step (1): Get rid of unrechle sttes. Stte Minimiztion 6, Stte is unrechle. Step (2): Get rid
More informationRecursively Enumerable and Recursive. Languages
Recursively Enumerble nd Recursive nguges 1 Recll Definition (clss 19.pdf) Definition 10.4, inz, 6 th, pge 279 et S be set of strings. An enumertion procedure for Turing Mchine tht genertes ll strings
More informationCS 301. Lecture 04 Regular Expressions. Stephen Checkoway. January 29, 2018
CS 301 Lecture 04 Regulr Expressions Stephen Checkowy Jnury 29, 2018 1 / 35 Review from lst time NFA N = (Q, Σ, δ, q 0, F ) where δ Q Σ P (Q) mps stte nd n lphet symol (or ) to set of sttes We run n NFA
More informationLecture 6 Regular Grammars
Lecture 6 Regulr Grmmrs COT 4420 Theory of Computtion Section 3.3 Grmmr A grmmr G is defined s qudruple G = (V, T, S, P) V is finite set of vribles T is finite set of terminl symbols S V is specil vrible
More information1 Online Learning and Regret Minimization
2.997 Decision-Mking in Lrge-Scle Systems My 10 MIT, Spring 2004 Hndout #29 Lecture Note 24 1 Online Lerning nd Regret Minimiztion In this lecture, we consider the problem of sequentil decision mking in
More informationState space systems analysis (continued) Stability. A. Definitions A system is said to be Asymptotically Stable (AS) when it satisfies
Stte spce systems nlysis (continued) Stbility A. Definitions A system is sid to be Asymptoticlly Stble (AS) when it stisfies ut () = 0, t > 0 lim xt () 0. t A system is AS if nd only if the impulse response
More informationCS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata
CS103B ndout 18 Winter 2007 Ferury 28, 2007 Finite Automt Initil text y Mggie Johnson. Introduction Severl childrens gmes fit the following description: Pieces re set up on plying ord; dice re thrown or
More informationExam 2, Mathematics 4701, Section ETY6 6:05 pm 7:40 pm, March 31, 2016, IH-1105 Instructor: Attila Máté 1
Exm, Mthemtics 471, Section ETY6 6:5 pm 7:4 pm, Mrch 1, 16, IH-115 Instructor: Attil Máté 1 17 copies 1. ) Stte the usul sufficient condition for the fixed-point itertion to converge when solving the eqution
More informationNondeterminism. Nondeterministic Finite Automata. Example: Moves on a Chessboard. Nondeterminism (2) Example: Chessboard (2) Formal NFA
Nondeterminism Nondeterministic Finite Automt Nondeterminism Subset Construction A nondeterministic finite utomton hs the bility to be in severl sttes t once. Trnsitions from stte on n input symbol cn
More informationNondeterminism and Nodeterministic Automata
Nondeterminism nd Nodeterministic Automt 61 Nondeterminism nd Nondeterministic Automt The computtionl mchine models tht we lerned in the clss re deterministic in the sense tht the next move is uniquely
More information1 APL13: Suffix Arrays: more space reduction
1 APL13: Suffix Arrys: more spce reduction In Section??, we sw tht when lphbet size is included in the time nd spce bounds, the suffix tree for string of length m either requires Θ(m Σ ) spce or the minimum
More informationI1 = I2 I1 = I2 + I3 I1 + I2 = I3 + I4 I 3
2 The Prllel Circuit Electric Circuits: Figure 2- elow show ttery nd multiple resistors rrnged in prllel. Ech resistor receives portion of the current from the ttery sed on its resistnce. The split is
More informationHow do we solve these things, especially when they get complicated? How do we know when a system has a solution, and when is it unique?
XII. LINEAR ALGEBRA: SOLVING SYSTEMS OF EQUATIONS Tody we re going to tlk bout solving systems of liner equtions. These re problems tht give couple of equtions with couple of unknowns, like: 6 2 3 7 4
More informationComputing the Optimal Global Alignment Value. B = n. Score of = 1 Score of = a a c g a c g a. A = n. Classical Dynamic Programming: O(n )
Alignment Grph Alignment Mtrix Computing the Optiml Globl Alignment Vlue An Introduction to Bioinformtics Algorithms A = n c t 2 3 c c 4 g 5 g 6 7 8 9 B = n 0 c g c g 2 3 4 5 6 7 8 t 9 0 2 3 4 5 6 7 8
More informationRegular expressions, Finite Automata, transition graphs are all the same!!
CSI 3104 /Winter 2011: Introduction to Forml Lnguges Chpter 7: Kleene s Theorem Chpter 7: Kleene s Theorem Regulr expressions, Finite Automt, trnsition grphs re ll the sme!! Dr. Neji Zgui CSI3104-W11 1
More informationLecture 3. In this lecture, we will discuss algorithms for solving systems of linear equations.
Lecture 3 3 Solving liner equtions In this lecture we will discuss lgorithms for solving systems of liner equtions Multiplictive identity Let us restrict ourselves to considering squre mtrices since one
More informationFinite Automata-cont d
Automt Theory nd Forml Lnguges Professor Leslie Lnder Lecture # 6 Finite Automt-cont d The Pumping Lemm WEB SITE: http://ingwe.inghmton.edu/ ~lnder/cs573.html Septemer 18, 2000 Exmple 1 Consider L = {ww
More informationDeterministic Finite-State Automata
Deterministic Finite-Stte Automt Deepk D Souz Deprtment of Computer Science nd Automtion Indin Institute of Science, Bnglore. 12 August 2013 Outline 1 Introduction 2 Exmple DFA 1 DFA for Odd number of
More informationBefore we can begin Ch. 3 on Radicals, we need to be familiar with perfect squares, cubes, etc. Try and do as many as you can without a calculator!!!
Nme: Algebr II Honors Pre-Chpter Homework Before we cn begin Ch on Rdicls, we need to be fmilir with perfect squres, cubes, etc Try nd do s mny s you cn without clcultor!!! n The nth root of n n Be ble
More informationChapter 4 Regular Grammar and Regular Sets. (Solutions / Hints)
C K Ngpl Forml Lnguges nd utomt Theory Chpter 4 Regulr Grmmr nd Regulr ets (olutions / Hints) ol. (),,,,,,,,,,,,,,,,,,,,,,,,,, (),, (c) c c, c c, c, c, c c, c, c, c, c, c, c, c c,c, c, c, c, c, c, c, c,
More informationTuring Machines Part One
Turing Mchines Prt One Wht problems cn we solve with computer? Regulr Lnguges CFLs Lnguges recognizble by ny fesible computing mchine All Lnguges Tht sme drwing, to scle. All Lnguges The Problem Finite
More information12.1 Nondeterminism Nondeterministic Finite Automata. a a b ε. CS125 Lecture 12 Fall 2016
CS125 Lecture 12 Fll 2016 12.1 Nondeterminism The ide of nondeterministic computtions is to llow our lgorithms to mke guesses, nd only require tht they ccept when the guesses re correct. For exmple, simple
More informationSUMMER KNOWHOW STUDY AND LEARNING CENTRE
SUMMER KNOWHOW STUDY AND LEARNING CENTRE Indices & Logrithms 2 Contents Indices.2 Frctionl Indices.4 Logrithms 6 Exponentil equtions. Simplifying Surds 13 Opertions on Surds..16 Scientific Nottion..18
More informationCISC 4090 Theory of Computation
9/6/28 Stereotypicl computer CISC 49 Theory of Computtion Finite stte mchines & Regulr lnguges Professor Dniel Leeds dleeds@fordhm.edu JMH 332 Centrl processing unit (CPU) performs ll the instructions
More information1 Structural induction
Discrete Structures Prelim 2 smple questions Solutions CS2800 Questions selected for Spring 2018 1 Structurl induction 1. We define set S of functions from Z to Z inductively s follows: Rule 1. For ny
More information5.7 Improper Integrals
458 pplictions of definite integrls 5.7 Improper Integrls In Section 5.4, we computed the work required to lift pylod of mss m from the surfce of moon of mss nd rdius R to height H bove the surfce of the
More informationMath Lecture 23
Mth 8 - Lecture 3 Dyln Zwick Fll 3 In our lst lecture we delt with solutions to the system: x = Ax where A is n n n mtrix with n distinct eigenvlues. As promised, tody we will del with the question of
More informationMatrix Solution to Linear Equations and Markov Chains
Trding Systems nd Methods, Fifth Edition By Perry J. Kufmn Copyright 2005, 2013 by Perry J. Kufmn APPENDIX 2 Mtrix Solution to Liner Equtions nd Mrkov Chins DIRECT SOLUTION AND CONVERGENCE METHOD Before
More informationHarvard University Computer Science 121 Midterm October 23, 2012
Hrvrd University Computer Science 121 Midterm Octoer 23, 2012 This is closed-ook exmintion. You my use ny result from lecture, Sipser, prolem sets, or section, s long s you quote it clerly. The lphet is
More informationProblem Set 3 Solutions
Chemistry 36 Dr Jen M Stndrd Problem Set 3 Solutions 1 Verify for the prticle in one-dimensionl box by explicit integrtion tht the wvefunction ψ ( x) π x is normlized To verify tht ψ ( x) is normlized,
More informationCS5371 Theory of Computation. Lecture 20: Complexity V (Polynomial-Time Reducibility)
CS5371 Theory of Computtion Lecture 20: Complexity V (Polynomil-Time Reducibility) Objectives Polynomil Time Reducibility Prove Cook-Levin Theorem Polynomil Time Reducibility Previously, we lernt tht if
More information5.1 Definitions and Examples 5.2 Deterministic Pushdown Automata
CSC4510 AUTOMATA 5.1 Definitions nd Exmples 5.2 Deterministic Pushdown Automt Definitions nd Exmples A lnguge cn be generted by CFG if nd only if it cn be ccepted by pushdown utomton. A pushdown utomton
More informationBellman Optimality Equation for V*
Bellmn Optimlity Eqution for V* The vlue of stte under n optiml policy must equl the expected return for the best ction from tht stte: V (s) mx Q (s,) A(s) mx A(s) mx A(s) Er t 1 V (s t 1 ) s t s, t s
More information12.1 Nondeterminism Nondeterministic Finite Automata. a a b ε. CS125 Lecture 12 Fall 2014
CS125 Lecture 12 Fll 2014 12.1 Nondeterminism The ide of nondeterministic computtions is to llow our lgorithms to mke guesses, nd only require tht they ccept when the guesses re correct. For exmple, simple
More informationCS415 Compilers. Lexical Analysis and. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University
CS415 Compilers Lexicl Anlysis nd These slides re sed on slides copyrighted y Keith Cooper, Ken Kennedy & Lind Torczon t Rice University First Progrmming Project Instruction Scheduling Project hs een posted
More informationNew data structures to reduce data size and search time
New dt structures to reduce dt size nd serch time Tsuneo Kuwbr Deprtment of Informtion Sciences, Fculty of Science, Kngw University, Hirtsuk-shi, Jpn FIT2018 1D-1, No2, pp1-4 Copyright (c)2018 by The Institute
More information1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true.
York University CSE 2 Unit 3. DFA Clsses Converting etween DFA, NFA, Regulr Expressions, nd Extended Regulr Expressions Instructor: Jeff Edmonds Don t chet y looking t these nswers premturely.. For ech
More informationLecture 08: Feb. 08, 2019
4CS4-6:Theory of Computtion(Closure on Reg. Lngs., regex to NDFA, DFA to regex) Prof. K.R. Chowdhry Lecture 08: Fe. 08, 2019 : Professor of CS Disclimer: These notes hve not een sujected to the usul scrutiny
More informationProperties of Integrals, Indefinite Integrals. Goals: Definition of the Definite Integral Integral Calculations using Antiderivatives
Block #6: Properties of Integrls, Indefinite Integrls Gols: Definition of the Definite Integrl Integrl Clcultions using Antiderivtives Properties of Integrls The Indefinite Integrl 1 Riemnn Sums - 1 Riemnn
More informationPart 5 out of 5. Automata & languages. A primer on the Theory of Computation. Last week was all about. a superset of Regular Languages
Automt & lnguges A primer on the Theory of Computtion Lurent Vnbever www.vnbever.eu Prt 5 out of 5 ETH Zürich (D-ITET) October, 19 2017 Lst week ws ll bout Context-Free Lnguges Context-Free Lnguges superset
More informationCSE : Exam 3-ANSWERS, Spring 2011 Time: 50 minutes
CSE 260-002: Exm 3-ANSWERS, Spring 20 ime: 50 minutes Nme: his exm hs 4 pges nd 0 prolems totling 00 points. his exm is closed ook nd closed notes.. Wrshll s lgorithm for trnsitive closure computtion is
More informationCoalgebra, Lecture 15: Equations for Deterministic Automata
Colger, Lecture 15: Equtions for Deterministic Automt Julin Slmnc (nd Jurrin Rot) Decemer 19, 2016 In this lecture, we will study the concept of equtions for deterministic utomt. The notes re self contined
More information5. (±±) Λ = fw j w is string of even lengthg [ 00 = f11,00g 7. (11 [ 00)± Λ = fw j w egins with either 11 or 00g 8. (0 [ ffl)1 Λ = 01 Λ [ 1 Λ 9.
Regulr Expressions, Pumping Lemm, Right Liner Grmmrs Ling 106 Mrch 25, 2002 1 Regulr Expressions A regulr expression descries or genertes lnguge: it is kind of shorthnd for listing the memers of lnguge.
More informationCS 330 Formal Methods and Models Dana Richards, George Mason University, Spring 2016 Quiz Solutions
CS 330 Forml Methods nd Models Dn Richrds, George Mson University, Spring 2016 Quiz Solutions Quiz 1, Propositionl Logic Dte: Ferury 9 1. (4pts) ((p q) (q r)) (p r), prove tutology using truth tles. p
More informationAgenda. Agenda. Regular Expressions. Examples of Regular Expressions. Regular Expressions (crash course) Computational Linguistics 1
Agend CMSC/LING 723, LBSC 744 Kristy Hollingshed Seitz Institute for Advnced Computer Studies University of Mrylnd HW0 questions? Due Thursdy before clss! When in doubt, keep it simple... Lecture 2: 6
More informationIntegral equations, eigenvalue, function interpolation
Integrl equtions, eigenvlue, function interpoltion Mrcin Chrząszcz mchrzsz@cernch Monte Crlo methods, 26 My, 2016 1 / Mrcin Chrząszcz (Universität Zürich) Integrl equtions, eigenvlue, function interpoltion
More informationLooking for All Palindromes in a String
Looking or All Plindromes in String Shih Jng Pn nd R C T Lee Deprtment o Computer Science nd Inormtion Engineering, Ntionl Chi-Nn University, Puli, Nntou Hsien,, Tiwn, ROC sjpn@lgdoccsiencnuedutw, rctlee@ncnuedutw
More informationThe graphs of Rational Functions
Lecture 4 5A: The its of Rtionl Functions s x nd s x + The grphs of Rtionl Functions The grphs of rtionl functions hve severl differences compred to power functions. One of the differences is the behvior
More informationFormal Methods in Software Engineering
Forml Methods in Softwre Engineering Lecture 09 orgniztionl issues Prof. Dr. Joel Greenyer Decemer 9, 2014 Written Exm The written exm will tke plce on Mrch 4 th, 2015 The exm will tke 60 minutes nd strt
More informationTerminal Velocity and Raindrop Growth
Terminl Velocity nd Rindrop Growth Terminl velocity for rindrop represents blnce in which weight mss times grvity is equl to drg force. F 3 π3 ρ L g in which is drop rdius, g is grvittionl ccelertion,
More information