
Deterministic Finite Automata And Regular Languages 1 Deterministic Finite Automaton (DFA) Input Tape String Output “Accept” Finite or Automaton “Reject” Costa Busch - LSU 2 Transition Graph a,b q5 a,b b a a b a a q0 q1 b q2 b q3 q4 initial accepting state state transition state Costa Busch - LSU 3 Alphabet Σ = {a,b} a,b q5 a,b b a a b a a q0 q1 b q2 b q3 q4 For every state, there is a transition for every symbol in the alphabet Costa Busch - LSU 4 head Initial Configuration Input Tape a b b a Input String a,b q5 a,b b a a b a a q0 q1 b q2 b q3 q4 Initial state Costa Busch - LSU 5 Scanning the Input a b b a a,b q5 a,b b a a b a a q0 q1 b q2 b q3 q4 Costa Busch - LSU 6 a b b a a,b q5 a,b b a a b a a q0 q1 b q2 b q3 q4 Costa Busch - LSU 7 a b b a a,b q5 a,b b a a b a a q0 q1 b q2 b q3 q4 Costa Busch - LSU 8 Input finished a b b a a,b q5 a,b b a a b a a q0 q1 b q2 b q3 q4 accept Last state determines the outcome Costa Busch - LSU 9 A Rejection Case a b a Input String a,b q5 a,b b a a b a a q0 q1 b q2 b q3 q4 Costa Busch - LSU 10 a b a a,b q5 a,b b a a b a a q0 q1 b q2 b q3 q4 Costa Busch - LSU 11 a b a a,b q5 a,b b a a b a a q0 q1 b q2 b q3 q4 Costa Busch - LSU 12 Input finished a b a a,b reject q5 a,b b a a b a a q0 q1 b q2 b q3 q4 Last state determines the outcome Costa Busch - LSU 13 Another Rejection Case Tape is empty (λ) Input Finished (no symbol read) a,b q5 a,b b a a b a a q0 q1 b q2 b q3 q4 reject Costa Busch - LSU 14 This automaton accepts only one string Language Accepted: L = {abba} a,b q5 a,b b a a b a a q0 q1 b q2 b q3 q4 Costa Busch - LSU 15 To accept a string: all the input string is scanned and the last state is accepting To reject a string: all the input string is scanned and the last state is non-accepting Costa Busch - LSU 16 Another Example L = {λ,ab,abba} a,b q5 a,b b a a b a a q0 q1 b q2 b q3 q4 Accept Accept Accept state state state Costa Busch - LSU 17 Empty Tape (λ) Input Finished a,b q5 a,b b a a b a a q0 q1 b q2 b q3 q4 accept Costa Busch - LSU 18 Another Example a a,b b a,b q0 q1 q2 Accept trap state state Costa Busch - LSU 19 a a b Input String a a,b b a,b q0 q1 q2 Costa Busch - LSU 20 a a b a a,b b a,b q0 q1 q2 Costa Busch - LSU 21 a a b a a,b b a,b q0 q1 q2 Costa Busch - LSU 22 Input finished a a b a a,b accept b a,b q0 q1 q2 Costa Busch - LSU 23 A rejection case b a b Input String a a,b b a,b q0 q1 q2 Costa Busch - LSU 24 b a b a a,b b a,b q0 q1 q2 Costa Busch - LSU 25 b a b a a,b b a,b q0 q1 q2 Costa Busch - LSU 26 Input finished b a b a a,b b a,b q0 q1 q2 reject Costa Busch - LSU 27 Language Accepted: L = {a nb :n ≥ 0} a a,b b a,b q0 q1 q2 Costa Busch - LSU 28 Another Example Alphabet: Σ = {1} 1 q0 q1 1 Language Accepted: EVEN = {x : x ∈ Σ* and x is even} = {λ, 11, 1111, 111111, …} Costa Busch - LSU 29 Formal Definition Deterministic Finite Automaton (DFA) M = (Q,Σ,δ ,q0,F) Q : set of states Σ : input alphabet λ ∉ Σ δ : transition function q0 : initial state F : set of accepting states Costa Busch - LSU 30 Set of States Q Example Q = {q0,q1,q2,q3,q4,q5} a,b q5 a,b b a a b a a q0 q1 b q2 b q3 q4 Costa Busch - LSU 31 Input Alphabet Σ λ ∉ Σ :the input alphabet never contains λ Example Σ = {a,b} a,b q5 a,b b a a b a a q0 q1 b q2 b q3 q4 Costa Busch - LSU 32 Initial State q0 Example a,b q5 a,b b a a b a a q0 q1 b q2 b q3 q4 Costa Busch - LSU 33 Set of Accepting States F ⊆ Q Example F = {q4} a,b q5 a,b b a a b a a q0 q1 b q2 b q3 q4 Costa Busch - LSU 34 Transition Function δ :Q×Σ → Q δ(q,x ) = qʹ q x qʹ Describes the result of a transition from state q with symbol x Costa Busch - LSU 35 Example: δ (q0,a) = q1 a,b q5 a,b b a a b a a q0 q1 b q2 b q3 q4 Costa Busch - LSU 36 δ (q0,b) = q5 a,b q5 a,b b a a b a a q0 q1 b q2 b q3 q4 Costa Busch - LSU 37 δ (q2,b) = q3 a,b q5 a,b b a a b a a q0 q1 b q2 b q3 q4 Costa Busch - LSU 38 Transition Table for δ symbols δ a b q0 q1 q5 q1 q5 q2 q2 q5 q3 a,b q3 q4 q5 states q4 q5 q5 q5 q5 q5 q5 a,b b a a b a a q0 q1 b q2 b q3 q4 Costa Busch - LSU 39 Extended Transition Function δ * :Q × Σ* →Q δ * (q,w ) = qʹ Describes the resulting state after scanning string w from state q Costa Busch - LSU 40 * Example: δ (q0,ab ) = q2 a,b q5 a,b b a a b a a q0 q1 b q2 b q3 q4 Costa Busch - LSU 41 * δ (q0,abbbaa ) = q5 a,b q5 a,b b a a b a a q0 q1 b q2 b q3 q4 Costa Busch - LSU 42 * δ (q1,bba ) = q4 a,b q5 a,b b a a b a a q0 q1 b q2 b q3 q4 Costa Busch - LSU 43 Special case: for any state q δ * (q,λ) = q Costa Busch - LSU 44 In general: δ * (q,w ) = qʹ implies that there is a walk of transitions w = σ1σ2 σk q σ1 σ 2 σ k qʹ states may be repeated q w qʹ Costa Busch - LSU 45 Language Accepted by DFA Language accepted by DFA M : it is denoted as L ( M ) and contains all the strings accepted by M We also say that M recognizes L(M ) Costa Busch - LSU 46 For a DFA M = (Q,Σ,δ ,q0,F) Language accepted by M : * * L(M ) = {w ∈ Σ : δ (q0,w )∈F } w q0 qʹ qʹ∈F Costa Busch - LSU 47 Language rejected by M : * * L(M) = {w ∈ Σ : δ (q0,w )∉F } w q0 qʹ qʹ∉F Costa Busch - LSU 48 More DFA Examples Σ = {a,b} a,b a,b q q0 0 L(M) = { } L(M) = Σ* Empty language All strings Costa Busch - LSU 49 Σ = {a,b} a,b a,b q0 q0 L(M) = {λ} Language of the empty string Costa Busch - LSU 50 Σ = {a,b} L(M )= { all strings with prefix ab } a,b q0 a q1 b q2 b a accept q3 a,b Costa Busch - LSU 51 L(M) = { all binary strings containing substring 001 } 0,1 1 0 1 λ 0 0 00 1 001 0 Costa Busch - LSU 52 L(M) = { all binary strings without substring 001 } 1 0 0,1 1 0 1 λ 0 00 001 0 Costa Busch - LSU 53 * L(M) = {awa :w ∈ {a,b} } a b b q0 a q2 q3 b a q4 a,b Costa Busch - LSU 54 Regular Languages Definition: A language L is regular if there is a DFA M that accepts it ( L ( M ) = L ) The languages accepted by all DFAs form the family of regular languages Costa Busch - LSU 55 Example regular languages: {abba} {λ,ab,abba} n {a b : n ≥ 0} {awa :w ∈ {a,b}* } { all strings in {a,b}* with prefix ab } { all binary strings without substring 001 } {x : x ∈ {1}* and x is even} { } {λ} {a,b}* There exist DFAs that accept these languages (see previous slides). Costa Busch - LSU 56 There exist languages which are not Regular: L={anbn : n ≥ 0} ADDITION = {x + y = z : x = 1n, y = 1m,z = 1k , n + m = k } There are no DFAs that accept these languages (we will prove this in a later class) Costa Busch - LSU 57 Properties of Regular Languages For regular languages L 1 and L 2 we will prove that: Union: L1 ∪ L2 Concatenation: L1L2 Are regular Star: L1 * Languages R Reversal: L1 Complement: L1 Intersection: L ∩ L Costa1 Busch - LSU2 59 We say: Regular languages are closed under Union: L1 ∪ L2 Concatenation: L1L2 Star: L1 * R Reversal: L1 Complement: L1 Intersection: L ∩ L Costa1 Busch - LSU2 60 A useful transformation: use one accept state NFA a 2 accept states a b b Equivalent a NFA 1 accept state a b b λ λ Costa Busch - LSU 61 In General NFA Equivalent NFA λ Single λ accepting λ state Costa Busch - LSU 62 Extreme case NFA without accepting state Add an accepting state without transitions Costa Busch - LSU 63 Take two languages Regular language L1 Regular language L2 L(M1) = L1 L(M2 ) = L2 NFA M1 NFA M 2 Single accepting state Single accepting state Costa Busch - LSU 64 Example M1 n ≥ 0 a n L1 ={a b} b M 2 b a L2 = {ba} Costa Busch - LSU 65 Union NFA for L1 ∪ L2 M1 λ λ M 2 Costa Busch - LSU 66 Example n NFA for L1 ∪ L2 ={a b}∪{ba} n L1 ={a b} a b λ λ L2 ={ba} b a Costa Busch - LSU 67 Concatenation NFA for L1L2 M1 M 2 λ Costa Busch - LSU 68 Example n n NFA for L1L2 ={a b}{ba} ={a bba} n L1 ={a b} a L2 ={ba} b λ b a Costa Busch - LSU 69 Star Operation w w w w NFA for L1 * = 1 2 k λ wi ∈ L1 M1 λ ∈ L1 * λ λ λ Costa Busch - LSU 70 Example n NFA for L1* ={a b}* λ n L1 ={a b} a λ b λ λ Costa Busch - LSU 71 Reverse R NFA for L1 L ʹ 1 M1 M1 1.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages121 Page
-
File Size-