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 or ccept stte (Kozen prefers "ccept"). To process string with this utomton, egin in the strt stte t the strt of the string. Wlk through the letters of the string, tking the trnsitions leled with the letters. If you re in n ccept stte t the end of the string, ccept it; otherwise reject it. S strt T U
For exmple, on string "" we go through the sttes SSTUT nd end in n ccept stte, so we ccept "". On the other hnd, with string "" we go through sttes STU nd we do not ccept. S strt T U On the other hnd, with string "" we strt in stte S, sty in S on input '', go to stte T on input '' nd then hve nowhere to go on input ''. Agin, we do not ccept the string. The only strings ccepted re those for which the utomton consumes ll of the letters in getting to n ccept stte.
The usul question for finite utomton is "Wht is the lnguge ccepted y the utomton?" S strt The lnguge ccepted y this utomton is the set of strings with ny numer of 's followed y n odd numer of 's. T U
In generl, "Deterministic Finite Automton" or DFA is quintuple (Q, S, d, s, F) where Q is finite set of sttes S is n lphet of symols d is trnsition function whose inputs re stte nd n element of S nd whose output is stte. This is represented y the rrows in our digrms. s is one of the sttes in Q. This is our strt stte. Note tht there is only one strt stte in n utomton. F is the set of ccept, or finl sttes.
This utomton processes strings in S * s follows: Let w= 0 1... n-1 e string in S *. Let q 0 e s (the strt stte), nd for i > 0 let q i = d(q i-1, i-1 ) The lst stte is q n. If q n is n element of F ccept the string w. This definition ssumes there is trnsition from every stte on every element of S. We cn mke ny utomton fit this y dding for ny missing trnsition trnsition to "ded" stte from which there is no exit. S str t T ded U,
It is useful to use the Lnguge of Regulr Expressions to descrie the strings ccepted y n utomton: 1. Any prticulr string w represents the lnguge {w} 2. If expressions E nd F represent lnguges L 1 nd L 2 then expression E+F represents L 1 L 2. 3. If expressions E nd F represent lnguges L 1 nd L 2 then expression EF represents the lnguge of strings formed y conctenting string from L 2 onto the end of string from L 1. 4. If expression E represents lnguge L then expression E * represents the lnguge of strings formed y conctenting 0 or more strings from L together. 5. If expression E represents lnguge L then expression E + represents the lnguge of strings formed y conctenting 1 or more strings from L together. E + =EE *
Exmple 1. S strt T U We sid efore tht this ccepts the lnguge of ny numer of 's followed y n odd numer of 's. This lnguge is represented y the regulr expression * () *
Exmple 2 S T U strt 1 0 1 This ccepts 10(10) * = (10) +
Exmple 3 S strt T This ccepts strings with n even numer of 's: ( * * ) *
Exmple 4: Find DFA tht ccepts 101, 11010, nd nothing else. 1 S T U V strt 1 0 0 1 0 W X Y 1 Z Note tht y imitting this exmple you could mke DFA tht ccepts ny prticulr finite lnguge.
Note tht it is esy to write progrm tht simultes DFA's ctions on string. You might hve one vrile tht represents the current stte nd for loop tht itertes through the letters of the string. For simple DFA with only few sttes you might hve ig conditionl sttement tht checks the vrious cses: if you re in stte foo with input letter r chnge the stte to z. For more generl utomton represent the trnsition function y 2D tle whose rows re indexed y the sttes nd whose columns re indexed y the lphet letters. Tle[foo][r] is the stte to trnsition to if you re in stte foo nd see input letter r.
Definition: We sy tht lnguge is regulr if it is the lnguge ccepted y some DFA. For exmples: S * is regulr for ny finite lphet S. Every finite lnguge is regulr. 10 * 1 is regulr. Strings of 0's nd 1's with n even numer of 1's is regulr.
Which of the following re regulr? For ech let the lphet e {0,1} Note tht we cn show set is regulr y producing the DFA tht ccepts it. We don't hve wy to show set isn't regulr. We will. ) Strings of length 2? yep ) Strings of even length? yep c) Strings of prime length? d) Strings with the sme numer of 0's s 1's? e) Strings with more 0's thn 1's? f) Strings tht contin 010 s sustrings? yep g) Strings with no more thn 2 0's? yep h) Strings tht re plindromes? i) Strings tht re plindromes of length 6 or less?