Flat

2,366 views

Published on

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,366
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
57
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Flat

  1. 1. Theory of Automata & Formal Languages 1
  2. 2. BOOKSTheory of computer Science: K.L.P.Mishra & N.ChandrasekharanIntro to Automata theory, Formal languages and computation: Ullman,Hopcroft MotwaniElements of theory of computation Lewis & papadimitrou 2
  3. 3. SyllabusIntroductionDeterministic and non deterministic Finite Automata, Regular Expression,Two way finite automata,Finite automata with output,properties of regular sets,pumping lemma, closure properties,Myhill nerode theorem 3
  4. 4. Context free Grammar: Derivation trees, Simplification formsPushdown automata: Def, Relationship between PDA and context free language,Properties, decision algorithmsTuring Machines: Turing machine model,Modification of turing machines,Church’s thesis,Undecidability,Recursive and recursively enumerable languages Post correspondence problems recursive functions 4
  5. 5. Chomsky Hierarchy: Regular grammars, unrestricted grammar, context sensitive language, relationship among languages 5
  6. 6. temporary memory input memory CPU output memory Program memory 6
  7. 7. temporary memory 3 f ( x) x z 2*2 4 f ( x) z * 2 8 input memory x 2 CPU output memoryProgram memory compute x x compute 2 x x 7
  8. 8. Automatontemporary memoryAutomaton input memory CPU output memory Program memory 8
  9. 9. temporary memory input memory Finite Automaton output memory 9
  10. 10. Different Kinds of AutomataAutomata are distinguished by the temporary memory • Finite Automata: no temporary memory • Pushdown Automata: stack • Turing Machines: random access memory 10
  11. 11. Pushdown Automaton Stack Push, Pop input memory Pushdown Automaton output memoryProgramming Languages (medium computing power) 11
  12. 12. Turing Machine Random Access Memory input memory Turing Machine output memoryAlgorithms (highest computing power) 12
  13. 13. Power of AutomataFinite Pushdown TuringAutomata Automata Machine 13
  14. 14. Power setsA power set is a set of setsS = { a, b, c }Powerset of S = the set of all the subsets of S2S = { , {a}, {b}, {c}, {a, b}, {a, c}, {b, c}, {a, b, c} }Observation: | 2S | = 2|S| ( 8 = 23 ) 14
  15. 15. Cartesian Product A = { 2, 4 } B = { 2, 3, 5 }A X B = { (2, 2), (2, 3), (2, 5), ( 4, 2), (4, 3), (4, 4) } |A X B| = |A| |B| Generalizes to more than two sets AXBX…XZ 15
  16. 16. RELATIONSR = {(x1, y1), (x2, y2), (x3, y3), …}xi R yie. g. if R = „>‟: 2 > 1, 3 > 2, 3 > 1In relations xi can be repeated 16
  17. 17. Equivalence Relations• Reflexive: xRx• Symmetric: xRy yRx• Transitive: x R Y and y R z xRzExample: R = „=„•x=x•x=y y=x• x = y and y = z x=z 17
  18. 18. Equivalence ClassesFor equivalence relation R equivalence class of x = {y : x R y}Example: R = { (1, 1), (2, 2), (1, 2), (2, 1), (3, 3), (4, 4), (3, 4), (4, 3) }Equivalence class of 1 = {1, 2}Equivalence class of 3 = {3, 4} 18
  19. 19. Example of Equivalence relationLet Z = set of integersR be defined on it as:R= {(x,y)| x Z, y Z and (x - y)is divisible by 5}This relation is known as” congruent modulo 5” 19
  20. 20. The equivalence classes are[0]R= {…-10, -5, 0, 5,10,…}[1]R = {…..,-9, -4, 1, 6, 11, 16….}[2]R= {….-8, -3,2,7,12,17…..}[3]R = {….-7, -2, 3, 8 ,13,…}[4]R = {….-6,-1,4,9,14,19,….}Z/R ={[0]R, [1]R, [2]R, [3]R, [4]R} 20
  21. 21. PROOF TECHNIQUES• Proof by induction• Proof by contradiction 21
  22. 22. InductionWe have statements P1, P2, P3, …If we know • for some k that P1, P2, …, Pk are true • for any n >= k that P1, P2, …, Pn imply Pn+1Then Every Pi is true 22
  23. 23. Trees root parent leaf childTrees have no cycles 23
  24. 24. Proof by Induction• Inductive basis Find P1, P2, …, Pk which are true• Inductive hypothesis Let‟s assume P1, P2, …, Pn are true, for any n >= k• Inductive step Show that Pn+1 is true 24
  25. 25. root Level 0 Level 1leaf Height 3 Level 2 Level 3 25
  26. 26. Binary Trees 26
  27. 27. ExampleTheorem: A binary tree of height n has at most 2n leaves.Proof: let l(i) be the number of leaves at level i l(0) = 0 l(3) = 8 27
  28. 28. Induction Step Level n hypothesis: l(n) <= 2nn+1 28
  29. 29. We want to show: l(i) <= 2i• Inductive basis l(0) = 1 (the root node)• Inductive hypothesis Let‟s assume l(i) <= 2i for all i = 0, 1, …, n• Induction step we need to show that l(n + 1) <= 2n+1 29
  30. 30. Induction Step Level n hypothesis: l(n) <= 2nn+1 l(n+1) <= 2 * l(n) <= 2 * 2n = 2n+1 30
  31. 31. Proof by ContradictionWe want to prove that a statement P is true • we assume that P is false • then we arrive at an incorrect conclusion • therefore, statement P must be true 31
  32. 32. ExampleTheorem: 2 is not rationalProof: Assume by contradiction that it is rational 2 = n/m n and m have no common factors We will show that this is impossible 32
  33. 33. 2 = n/m 2 m 2 = n2 n is evenTherefore, n2 is even n=2k m is even2 m2 = 4k2 m2 = 2k2 m=2p Thus, m and n have common factor 2 Contradiction! 33
  34. 34. Basic TermsAlphabet: A finite non empty set of elements. ={a,b,c,d,…z} 34
  35. 35. • String: A sequence of letters – Examples: “cat”, “dog”, “house”, … – Defined over an alphabet: a, b, c,, z Language: It is a set of strings on somealphabet 35
  36. 36. Alphabets and Strings• We will use small alphabets: a, b• Strings a ab u ab abba v bbbaaa baba w abba aaabbbaabab 36
  37. 37. String Operationsw a1a2 an abbav b1b2 bm bbbaaa Concatenationwv a1a2 anb1b2 bm abbabbbaaa 37
  38. 38. w a1a2 an ababaaabbb Reverse Rw an  a2 a1 bbbaaababa 38
  39. 39. String Length w a1a2 an w n• Length: abba 4• Examples: aa 2 a 1 39
  40. 40. Recursive Definition of Length a 1For any letter: wa wa w 1 abba abb 1For any string : ab 1 1Example: a 1 1 1 1 1 1 1 4 40
  41. 41. Length of Concatenation uv u v u aab, u 3 v abaab, v 5• Example: uv aababaab 8 uv u v 3 5 8 41
  42. 42. Proof of Concatenation Length uv u v• Claim: v• Proof: By induction on the length v 1 – Induction basis: – From definition of length: uv u 1 u v 42
  43. 43. uv u v– Inductive hypothesis: v 1,2,, n • for uv u v– Inductive step: we will prove–– for v n 1 43
  44. 44. Inductive Step v wa w n, a 1• Write , where uv uwa uw 1• From definition of length: wa w 1 uw u w• From inductive hypothesis: uv• Thus: u w 1 u wa u v 44
  45. 45. Empty String• A string with no letters: 0• Observations: w w w abba abba abba 45
  46. 46. Substring• Substring of string: – a subsequence of consecutive characters abbab ab• String Substring abbab abba abbab b abbab bbab 46
  47. 47. Prefix and Suffix• Prefixes Suffixes abbab w uv abbab a bbab prefix suffix ab bab abb ab abba b 47 abbab
  48. 48. Another Operation wn ww  w    n 2 abba abbaabba• Example: 0 w• Definition: – 0 abba 48
  49. 49. The * Operation• * : the set of all possible strings from• alphabet a, b* , a, b, aa, ab, ba, bb, aaa, aab,• 49
  50. 50. The + Operation : the set of all possible strings from alphabet except a, b* , a, b, aa, ab, ba, bb, aaa, aab, * a, b, aa, ab, ba, bb, aaa, aab, 50
  51. 51. Language *• A language is any subset of a, b• Example: * , a, b, aa, ab, ba, bb, aaa, a, aa, aab• Languages: { , abba, baba, aa, ab, aaaaaa} 51
  52. 52. Another Examplen n L {a b : n 0}• An infinite languageab L abb Laabbaaaaabbbbb 52
  53. 53. Operations on Languages• The usual set operationsa, ab, aaaa  bb, ab {a, ab, bb, aaaa}a, ab, aaaa  bb, ab {ab}a, ab, aaaa bb, ab a, aaaa• Complement: L * L a, ba , b, aa, ab, bb, aaa, 53
  54. 54. Reverse R R L {w : w L}• Definition: R ab, aab, baba ba, baa, abab• Examples: n n L {a b : n 0} R n n L {b a : n 0} 54
  55. 55. Concatenation L1L2 xy : x L1, y L2• Definition: a, ab, ba b, aa• Example: ab, aaa, abb, abaa, bab, baaa 55
  56. 56. Another Operation Ln LL  L  n• Definition: 3 a, b a, b a, b a, b aaa, aab, aba, abb, baa, bab, bba, bbb L0• Special case: 0 a , bba , aaa 56
  57. 57. More Examples n n L {a b : n 0}• 2 n n m m L {a b a b : n, m 0} 2 aabbaaabbb L 57
  58. 58. Star-Closure (Kleene *) 0 1 2 L* L  L  L • Definition: ,• Example: a, bb,a, bb * aa, abb, bba, bbbb,• aaa, aabb, abba, abbbb, 58
  59. 59. Positive Closure 1 2 L L  L  L*• Definition: a, bb,a, bb aa, abb, bba, bbbb, aaa, aabb, abba, abbbb, 59
  60. 60. Finite Automaton Input• String Output Finite String Automaton 60
  61. 61. Finite Accepter Input• String Output “Accept” Finite or Automaton “Reject” 61
  62. 62. Transition Graph a,b Abba -Finite Accepter• q5 a a,b b a b q0 a q1 b q2 b q3 a q4 initial final state state transition state “accept” 62
  63. 63. Initial Configuration Input Stringa b b a• a,b q5 a a,b b a b q0 a q1 b q2 b q3 a q4 63
  64. 64. Reading the Inputa b b a• a,b q5 a a,b b a b q0 a q1 b q2 b q3 a q4 64
  65. 65. a b b a a,b q5 a a,b b a b q0 a q1 b q2 b q3 a q4 65
  66. 66. a b b a a,b q5 a a,b b a b q0 a q1 b q2 b q3 a q4 66
  67. 67. a b b a a,b q5 a a,b b a b q0 a q1 b q2 b q3 a q4 67
  68. 68. Input finisheda b b a a,b q5 a a,b b a b q0 a q1 b q2 b q3 a q4 Output: “accept”68
  69. 69. Rejectiona b a• a,b q5 a a,b b a b q0 a q1 b q2 b q3 a q4 69
  70. 70. a b a• a,b q5 a a,b b a b q0 a q1 b q2 b q3 a q4 70
  71. 71. a b a• a,b q5 a a,b b a b q0 a q1 b q2 b q3 a q4 71
  72. 72. a b a• a,b q5 a a,b b a b q0 a q1 b q2 b q3 a q4 72
  73. 73. Input finisheda b a a,b Output: q5 “reject” a a,b b a b q0 a q1 b q2 b q3 a q4 73
  74. 74. Another Examplea a b a a,b q0 b a,b q1 q2 74
  75. 75. a a b a a,b q0 b a,b q1 q2 75
  76. 76. a a b a a,b q0 b a,b q1 q2 76
  77. 77. a a b a a,b q0 b a,b q1 q2 77
  78. 78. Input finisheda a b a a,b Output: “accept” q0 b a,b q1 q2 78
  79. 79. Rejectionb a b a a,b q0 b a,b q1 q2 79
  80. 80. b a b a a,b q0 b a,b q1 q2 80
  81. 81. b a b a a,b q0 b a,b q1 q2 81
  82. 82. b a b a a,b q0 b a,b q1 q2 82
  83. 83. Input finishedb a b a a,b q0 b a,b q1 q2 Output: “reject” 83
  84. 84. • Deterministic Finite Accepter (DFA) M Q, , , q0 , FQ : Finite set of states : input alphabet : transition function :Q X Qq0 : initial state is a member of QF : set of final states 84
  85. 85. Input Alphabet a, b a,b q5 b a a,b a bq0 a q1 b q2 b q3 a q4 85
  86. 86. Set of States QQ q0 , q1, q2 , q3 , q4 , q5 a,b q5 a a,b b a b q0 a q1 b q2 b q3 a q4 86
  87. 87. Initial State q0 a,b q5 a a,b b a bq0 a q1 b q2 b q3 a q4 87
  88. 88. Set of Final States FF q4 a,b q5 a a,b b a b q0 a q1 b q2 b q3 a q4 88
  89. 89. Transition Function :Q Q a,b q5 b a a,b a bq0 a q1 b q2 b q3 a q4 89
  90. 90. q0 , a q1 a,b q5 b a a,b a bq0 a q1 b q2 b q3 a q4 90
  91. 91. q0 , b q5 a,b q5 b a a,b a bq0 a q1 b q2 b q3 a q4 91
  92. 92. q2 , b q3 a,b q5 b a a,b a bq0 a q1 b q2 b q3 a q4 92
  93. 93. a b Transition Functionq0 q1 q5q1• q5 q2q2 q2 q3q3 q4 q5 a,bq4 q5 q5q5 q5 q5 q5 b a a,b a b q0 a q1 b q2 b q3 a q4 93
  94. 94. Extended Transition Function * *: Q * Q a,b q5 b a a,b a b q0 a q1 b q2 b q3 a q4 94
  95. 95. * q0 , ab q2 a,b q5 b a a,b a bq0 a q1 b q2 b q3 a q4 95
  96. 96. * q0 , abba q4 a,b q5 b a a,b a bq0 a q1 b q2 b q3 a q4 96
  97. 97. * q0 , abbbaa q5 a,b q5 b a a,b a bq0 a q1 b q2 b q3 a q4 97
  98. 98. Observation: There is a walk from q0 to q1 with label abbbaa * q0 , abbbaa q5 a,b q5 b a a,b a b q0 a q1 b q2 b q3 a q4 98
  99. 99. Recursive Definition * q, q• * q, wa ( * (q, w), a ) a,b q5 b a a,b a b q0 a q1 b q2 b q3 a q4 99
  100. 100. * q0 , ab * (q0 , a ), b * q0 , ,a ,b q0 , a , b q1 , bq2 a,b q5 b a a,b a b q0 a q1 b q2 b q3 a q4 100
  101. 101. Languages Accepted by DFAs• Take DFA M• Definition: – The language L M contains – all input strings accepted by MLM – = { strings that drive M to a final state} 101
  102. 102. ExampleLM abba M• a,b q5 b a a,b a b q0 a q1 b q2 b q3 a q4 accept 102
  103. 103. Another ExampleLM , ab, abba M• a,b q5 b a a a,b b q0 a q1 b q2 b q3 a q4 accept accept accept 103
  104. 104. Formally• For a DFA Language accepted by M : LM w * : * q0 , w F M Q, , , q0 , Falphabet transition initial final function state states 104
  105. 105. Observation• Language accepted by M: LM w * : * q0 , w F• Language rejected by M : LM w * : * q0 , w F 105
  106. 106. • More Examples n LM {a b : n 0} a a,b q0 b a,b q1 q2 accept trap state or dead state 106
  107. 107. LM = { all strings with prefix ab }• a,b q0 a q1 b q2 b a accept q3 a,b 107
  108. 108. L M = { all strings without substring 001 }• 1 0 0,1 1 0 1 0 00 001 0 108
  109. 109. Regular Languages• A language L is regular if there is• a DFA M such that L L M• All regular languages form a language family – 109
  110. 110. Example L awa : w a, b * a• The language b• is regular: b q0 a q2 q3• b a q4 a,b 110
  111. 111. Non Deterministic Automata 111
  112. 112. Non Deterministic Finite AccepterM Q, , , q0 , F Q :Q 2 112
  113. 113. Nondeterministic Finite Accepter (NFA)Alphabet = {a} q1 a q2 a q0 a q3 113
  114. 114. Nondeterministic Finite Accepter (NFA)Alphabet = {a} Two choices q1 a q2 a q0 a q3 114
  115. 115. Nondeterministic Finite Accepter (NFA)Alphabet = {a} Two choices q1 a q2 No transition a q0 a q3 No transition 115
  116. 116. First Choicea a q1 a q2 a q0 a q3 116
  117. 117. First Choicea a q1 a q2 a q0 a q3 117
  118. 118. First Choicea a q1 a q2 a q0 a q3 118
  119. 119. First Choice a aAll input is consumed q1 a q2 “accept” a q0 a q3 119
  120. 120. Second Choicea a q1 a q2 a q0 a q3 120
  121. 121. Second Choicea a q1 a q2 a q0 a q3 121
  122. 122. Second Choicea a q1 a q2 a q0 a No transition: q3 the automaton hangs 122
  123. 123. Second Choice a aInput cannot be consumed q1 a q2 a q0 a q3 “reject” 123
  124. 124. An NFA accepts a string:when there is a computation of the NFAthat accepts the string•All the input is consumed and the automaton is in a final state 124
  125. 125. An NFA rejects a string:when there is no computation of the NFAthat accepts the string • All the input is consumed and the automaton is in a non final state • The input cannot be consumed 125
  126. 126. Example aa is accepted by the NFA: “accept” q1 a q2 q1 a q2 a a q0 q0 a a q3 q3 “reject”because this computationaccepts aa 126
  127. 127. Rejection examplea q1 a q2 a q0 a q3 127
  128. 128. First Choicea q1 a q2 a q0 a q3 128
  129. 129. First Choicea “reject” q1 a q2 a q0 a q3 129
  130. 130. Second Choicea q1 a q2 a q0 a q3 130
  131. 131. Second Choicea q1 a q2 a q0 a q3 131
  132. 132. Second Choicea q1 a q2 a q0 a q3 “reject” 132
  133. 133. Example a is rejected by the NFA: “reject” q1 a q2 q1 a q2 a aq0 q0 a a q3 “reject” q3All possible computations lead to rejection 133
  134. 134. Rejection examplea a a q1 a q2 a q0 a q3 134
  135. 135. First Choicea a a q1 a q2 a q0 a q3 135
  136. 136. First Choicea a a q1 a q2 a q0 a No transition: the automaton hangs q3 136
  137. 137. First Choice a a aInput cannot be consumed q1 a q2 “reject” a q0 a q3 137
  138. 138. Second Choicea a a q1 a q2 a q0 a q3 138
  139. 139. Second Choicea a a q1 a q2 a q0 a q3 139
  140. 140. Second Choicea a a q1 a q2 a q0 a No transition: q3 the automaton hangs 140
  141. 141. Second Choice a a aInput cannot be consumed q1 a q2 a q0 a q3 “reject” 141
  142. 142. aaa is rejected by the NFA: “reject” q1 a q2 q1 a q2 a a q0 q0 a a q3 q3 “reject”All possible computations lead to rejection 142
  143. 143. Language accepted: L {aa} q1 a q2 a q0 a q3 143
  144. 144. Lambda →Transitionsq0 a q1 q2 a q3 144
  145. 145. a a q0 a q1 q2 a q3 145
  146. 146. a a q0 a q1 q2 a q3 146
  147. 147. (read head doesn‟t move)a a q0 a q1 q2 a q3 147
  148. 148. a a q0 a q1 q2 a q3 148
  149. 149. all input is consumed a a “accept” q0 a q1 q2 a q3String aa is accepted 149
  150. 150. Rejection Examplea a a q0 a q1 q2 a q3 150
  151. 151. a a a q0 a q1 q2 a q3 151
  152. 152. (read head doesn‟t move)a a a q0 a q1 q2 a q3 152
  153. 153. a a a q0 a q1 q2 a q3 No transition: the automaton hangs 153
  154. 154. Input cannot be consumed a a a “reject” q0 a q1 q2 a q3String aaa is rejected 154
  155. 155. Language accepted: L {aa} q0 a q1 q2 a q3 155
  156. 156. Another NFA Exampleq0 a q1 b q2 q3 156
  157. 157. a b q0 a q1 b q2 q3 157
  158. 158. a b q0 a q1 b q2 q3 158
  159. 159. a b q0 a q1 b q2 q3 159
  160. 160. a b “accept” q0 a q1 b q2 q3 160
  161. 161. Another Stringa b a b q0 a q1 b q2 q3 161
  162. 162. a b a b q0 a q1 b q2 q3 162
  163. 163. a b a b q0 a q1 b q2 q3 163
  164. 164. a b a b q0 a q1 b q2 q3 164
  165. 165. a b a b q0 a q1 b q2 q3 165
  166. 166. a b a b q0 a q1 b q2 q3 166
  167. 167. a b a b q0 a q1 b q2 q3 167
  168. 168. a b a b “accept” q0 a q1 b q2 q3 168
  169. 169. Language accepted L ab, abab, ababab, ... abq0 a q1 b q2 q3 169
  170. 170. Another NFA Example 0q0 q1 0, 1 q2 1 170
  171. 171. Language acceptedL(M ) = {λ, 10, 1010, 101010, ...} = {10}* 0 q0 q1 0, 1 q2 1 171
  172. 172. Remarks: •The symbol never appears on the input tape •Extreme automata: M1 M2 q0 q0 L(M1 ) = {} L(M 2 ) = {λ} 172
  173. 173. •NFAs are interesting because we can express languages easier than DFAs a,b NFA M1 DFA M2 q2 q0 a q1 b a,b q0 a q1 L( M1 ) = {a} L( M 2 ) = {a} 173
  174. 174. Formal Definition of NFAs M Q, , , q0 , FQ : Set of states, i.e. q0 , q1, q2 : Input alphabet, i.e. a, b : Transition functionq0 : Initial stateF : Final states 174
  175. 175. Transition Function q0 , 1 q1 0q0 q1 0, 1 q 2 1 175
  176. 176. (q1,0) {q0 , q2} 0q0 q1 0, 1 q 2 1 176
  177. 177. (q0 , ) {q0 , q2} 0q0 q1 0, 1 q 2 1 177
  178. 178. (q2 ,1) 0q0 q1 0, 1 q 2 1 178
  179. 179. Extended Transition Function * * q0 , a q1• q4 q5 a a q0 a q1 b q2 q3 179
  180. 180. * q0 , aa q4 , q5 q4 q5 a aq0 a q1 b q2 q3 180
  181. 181. * q0 , ab q2 , q3 , q0 q4 q5 a aq0 a q1 b q2 q3 181
  182. 182. Formally qj * qi , wIt holdsif and only if there is a walk from qi to q j with label w 182
  183. 183. The Language of an NFA MF q0 ,q5 q4 q5 • a a q0 a q1 b q2 q3 * q0 , aa q4 , q5 aa L(M ) 183
  184. 184. F q0 ,q5 q4 q5 a a q0 a q1 b q2 q3* q0 , ab q2 , q3 , q0 ab L M 184
  185. 185. F q0 ,q5 q4 q5 • a a q0 a q1 b q2 q3* q0 , abaa q4 , q5 aaba L(M ) 185
  186. 186. F q0 ,q5 q4 q5 a a q0 a q1 b q2 q3 * q0 , aba q1 aba L M 186
  187. 187. q4 q5 a a q0 a q1 b q2 q3LM aa ab * ab aa 187
  188. 188. Formally• The language accepted by NFA M is: LM w1, w2 , w3 ,... * (q0 , wm ) {qi , q j ,...}• where• and there is some qk F (final state) 188
  189. 189. w LM * (q0 , w) • qi w qk qk F q0 w w qj 189
  190. 190. Equivalence of NFAs and DFAs 190
  191. 191. Equivalence of Machines• For DFAs or NFAs:• Machine M1 is equivalent to machine M 2• if L M1 L M2• 191
  192. 192. NFA M1L M1 {10} * 0 q0 q1 0, 1 q2 • 1 DFA M2 0,1L M2 {10}* 0 q0 q1 1 q2 1 0 192
  193. 193. • Since L M1 L M2 10 *• machines M1 and M 2are equivalent 0 NFA M1 q0 q1 0, 1 q2 1 0,1 0 DFA M2 q0 q1 1 q2 1 0 193
  194. 194. Equivalence of NFAs and DFAsQuestion: NFAs = DFAs ? Same power? Accept the same languages? 194
  195. 195. Equivalence of NFAs and DFAsQuestion: NFAs = DFAs ? YES! Same power? Accept the same languages? 195
  196. 196. We will prove:Languages Languagesaccepted acceptedby NFAs by DFAs NFAs and DFAs have the same computation power 196
  197. 197. Step 1 Languages Languages accepted accepted by NFAs by DFAsProof: Every DFA is trivially an NFA A language accepted by a DFA is also accepted by an NFA 197
  198. 198. Step 2 Languages Languages accepted accepted by NFAs by DFAsProof: Any NFA can be converted to an equivalent DFA A language accepted by an NFA is also accepted by a DFA 198
  199. 199. NFA to DFANFA M a q0 a q1 q2 • bDFA M q0 199
  200. 200. NFA M a q0 a q1 q2 • bDFA M q0 a q1, q2 200
  201. 201. NFA M a q0 a q1 q2 • bDFA M q0 a q1, q2 b 201
  202. 202. NFA M a q0 a q1 q2 • b aDFA M q0 a q1, q2 b 202
  203. 203. NFA M a q0 a q1 q2 • b b aDFA M q0 a q1, q2 b 203
  204. 204. NFA M a q0 a q1 q2 • b b aDFA M q0 a q1, q2 b a, b 204
  205. 205. NFA M a LM L(M ) q0 a q1 q2 • b aDFA M b q0 a q1, q2 b a, b 205
  206. 206. NFA to DFA: Remarks• We are given an NFA M• We want to convert it to an equivalent DFA M LM L(M ) 206
  207. 207. • If the NFA has states q0 , q1, q2 ,...• the DFA has states in the power set• , q0 , q1 , q1, q2 , q3 , q4 , q7 ,.... 207
  208. 208. Procedure NFA to DFA•• 1. Initial state of NFA: q0•• Initial state of DFA: q0 208
  209. 209. NFA M a q0 a q1 q2 • bDFA M q0 209
  210. 210. Procedure NFA to DFA• 2. For every DFA’s state {qi , q j ,..., qm}• Compute in the NFA * qi , a , * q j,a , {qi , q j ,..., qm}• ... {qi , q j ,..., qm}, a {qi , q j ,..., qm}• 210 Add transition to DFA
  211. 211. NFA M a q0 a q1 q2 • b * (q0 , a ) {q1, q2 }DFA M q0 a q1, q2 q0 , a q1, q2 211
  212. 212. Procedure NFA to DFA• Repeat Step 2 for all letters in alphabet,• until• no more transitions can be added. 212
  213. 213. NFA M a q0 a q1 q2 • b b aDFA M q0 a q1, q2 b a, b 213
  214. 214. Procedure NFA to DFA• 3. For any DFA state {qi , q j ,..., qm}• If some q j is a final state in the NFA• Then, {qi , q j ,..., qm }• 214 is a final state in the DFA
  215. 215. NFA M a q0 a q1 q2 q1 F • b aDFA M b q0 a q1, q2 b q1, q2 F a, b 215
  216. 216. Theorem Take NFA M •Apply procedure to obtain DFA MThen M and M are equivalent : LM LM 216
  217. 217. Finally We have provenLanguages Languagesaccepted acceptedby NFAs by DFAs 217
  218. 218. We have provenLanguages Languagesaccepted acceptedby NFAs by DFAs Regular Languages 218
  219. 219. We have proven Languages Languages accepted accepted by NFAs by DFAsRegular Languages Regular Languages 219
  220. 220. We have proven Languages Languages accepted accepted by NFAs by DFAsRegular Languages Regular Languages Thus, NFAs accept the regular languages 220
  221. 221. Single Final Statefor NFAs and DFAs 221
  222. 222. Observation• Any Finite Automaton (NFA or DFA)• can be converted to an equivalent NFA• with a single final state 222
  223. 223. Example a NFAa bb a Equivalent NFAa bb 223
  224. 224. In GeneralNFAEquivalent NFA Single final state 224
  225. 225. Extreme CaseNFA without final state Add a final state Without transitions 225
  226. 226. Some Properties ofRegular Languages 226
  227. 227. propertiesFor regular languages L1 and L 2we will prove that: Union: L1 L2 Concatenation: L1L2 Are regular Languages Star: L1 * 227
  228. 228. We Say:Regular languages are closed under Union: L1 L2 Concatenation: L1L2 Star: L1 * 228
  229. 229. Properties For regular languages L1 and L2 we will prove that: Union: L1 L2 Are regularConcatenation: L1L2 Languages Star: L1 * 229
  230. 230. Regular language L1 Regular language L2 L M1 L1 L M2 L2 NFA M1 NFA M2 Single final state Single final state 230
  231. 231. Example a n M1L1 {a b} b M2L2 ba b a 231
  232. 232. L1 L2 Union M1• NFA for M2 232
  233. 233. n L1 L2 {a b} {ba}NFA for n • L1 {a b} a b L2 {ba} b a 233
  234. 234. Concatenation L1L2• NFA for M1 M2 234
  235. 235. Example n n L1L2 {a b}{ba} {a bba}•• NFA for n L1 {a b} a L2 {ba} b b a 235
  236. 236. Star Operation• NFA for L * 1 L1 * M1 236
  237. 237. Example n L1* {a b} *• NFA for n L1 {a N>=} b0 a b 237
  238. 238. Procedure: NFA to DFA1 Create a graph with vertex {q0}.Identify this vertex as initial vertex of DFA.2 Repeat the following steps until no more edges are missing.Take any vertex {qi,qj,….qk} of G that has no outgoing edge for some symbol a of the alphabet. Compute *(qi, a), * (qj, a)…. *(qk, a) Then form the union of all these yielding the set * {ql, qm, …qn}. Create a vertex for G labeled {ql, qm,…qn} if it does not already exist. Add to G an edge from {qi, qj,…qk} to {ql,qm…qn} and label it with a.3 Every state of G whose label contains any qf of F is identified as a final vertex of DFA.4 If NFA accepts then vertex {q0} in G is also made a 238 final vertex.
  239. 239. 1 0q0 q1 q2 0,1 0,1 239
  240. 240. StartEquivalent q0 1 0DFA q {q0, 1 q1} 1 0,1 1 q2 0 0,1 0 q0,q1,q2 1 q1,q2 0 0,1 240

×