Upcoming SlideShare
Loading in …5
×

# Nfa egs

475 views

Published on

cd4

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
Your message goes here
• Be the first to comment

• Be the first to like this

No Downloads
Views
Total views
475
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
22
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Nfa egs

1. 1. Non Deterministic Automata 1
2. 2. Nondeterministic Finite Accepter (NFA) Alphabet = {a} a q0 q1 a q2 a q3 2
3. 3. Nondeterministic Finite Accepter (NFA) Alphabet = {a} Two choices a q0 q1 a q2 a q3 3
4. 4. Nondeterministic Finite Accepter (NFA) Alphabet = {a} Two choices a q0 q1 a q2 No transition a q3 No transition 4
5. 5. First Choice a a a q0 q1 a q2 a q3 5
6. 6. First Choice a a a q0 q1 a q2 a q3 6
7. 7. First Choice a a a q0 q1 a q2 a q3 7
8. 8. First Choice a a a q0 q1 a q2 “accept” a q3 8
9. 9. Second Choice a a a q0 q1 a q2 a q3 9
10. 10. Second Choice a a a q0 q1 a q2 a q3 10
11. 11. Second Choice a a a q0 q1 a a q3 q2 No transition: the automaton hangs 11
12. 12. Second Choice a a a q0 q1 a q2 a q3 “reject” 12
13. 13. Observation An NFA accepts a string if there is a computation of the NFA that accepts the string 13
14. 14. Example aa is accepted by the NFA: a q0 q1 a q2 a q3 14
15. 15. Lambda Transitions q0 a q1 λ q1 a q3 15
16. 16. a a q0 a q1 λ q2 a q3 16
17. 17. a a q0 a q1 λ q2 a q3 17
18. 18. (read head doesn’t move) a a q0 a q1 λ q2 a q3 18
19. 19. a a q0 a q1 λ q2 a q3 19
20. 20. a a “accept” q0 a String aa q1 λ q2 a q3 is accepted 20
21. 21. Language accepted: q0 a q1 λ L = {aa} q2 a q3 21
22. 22. Another NFA Example q0 a b q1 q2 λ q3 λ 22
23. 23. a b q0 a b q1 q2 λ q3 λ 23
24. 24. a b q0 a b q1 q2 λ q3 λ 24
25. 25. a b q0 a b q1 q2 λ q3 λ 25
26. 26. a b “accept” q0 a b q1 q2 λ q3 λ 26
27. 27. Another String a b a b q0 a b q1 q2 λ q3 λ 27
28. 28. a b a b q0 a b q1 q2 λ q3 λ 28
29. 29. a b a b q0 a b q1 q2 λ q3 λ 29
30. 30. a b a b q0 a b q1 q2 λ q3 λ 30
31. 31. a b a b q0 a b q1 q2 λ q3 λ 31
32. 32. a b a b q0 a b q1 q2 λ q3 λ 32
33. 33. a b a b q0 a b q1 q2 λ q3 λ 33
34. 34. a b a b “accept” q0 a b q1 q2 λ q3 λ 34
35. 35. Language accepted L = { ab, abab, ababab, ...} = { ab} q0 a + b q1 q2 λ q3 λ 35
36. 36. Another NFA Example 0 q0 1 q1 0, 1 q2 λ 36
37. 37. Language accepted L = { λ , 10, 1010, 101010, ...} = {10} * 0 q0 1 q1 0, 1 q2 λ 37
38. 38. Formal Definition of NFAs M = ( Q, Σ, δ , q0 , F ) Q: Set of states, i.e. { q0 , q1, q2 } Σ: Input aplhabet, i.e. { a, b} δ: Transition function q0 : Initial state F: Final states 38
39. 39. Transition Function δ δ ( q0 , 1) = { q1} 0 q0 1 q1 0, 1 q 2 λ 39
40. 40. δ (q1,0) = {q0 , q2 } 0 q0 1 q1 0, 1 q 2 λ 40
41. 41. δ (q0 , λ ) = {q0 , q2 } 0 q0 1 q1 0, 1 q 2 λ 41
42. 42. δ (q2 ,1) = ∅ 0 q0 1 q1 0, 1 q 2 λ 42
43. 43. Extended Transition Function δ * δ * ( q0 , a ) = { q1} q5 q4 a q0 a a b q1 λ q2 λ q3 43
44. 44. δ * ( q0 , aa ) = { q4 , q5 } q5 q4 a q0 a a b q1 λ q2 λ q3 44
45. 45. δ * ( q0 , ab ) = { q2 , q3 , q0 } q5 q4 a q0 a a b q1 λ q2 λ q3 45
46. 46. Formally It holds q j ∈ δ * ( qi , w) if and only if there is a walk from with label w qi to q j 46
47. 47. The Language of an NFA M F = { q0 ,q5 } q5 q4 a q0 a a b q1 q2 λ q3 λ δ * ( q0 , aa ) = { q4 , q5 } aa ∈ L(M ) 47
48. 48. F = { q0 ,q5 } q5 q4 a q0 a a b q1 q2 λ q3 λ δ * ( q0 , ab ) = { q2 , q3 , q0 } ab ∈ L( M ) 48
49. 49. F = { q0 ,q5 } q5 q4 a q0 a a b q1 q2 λ q3 λ δ * ( q0 , abaa ) = { q4 , q5 } aaba ∈ L(M ) 49
50. 50. F = { q0 ,q5 } q5 q4 a q0 a a b q1 q2 λ q3 λ δ * ( q0 , aba ) = { q1} aba ∉ L( M ) 50
51. 51. q5 q4 a q0 a a b q1 λ q2 q3 λ L( M ) = { aa} ∪ { ab} * ∪ { ab} + { aa} 51
52. 52. Formally The language accepted by NFA M is: L( M ) = { w1, w2 , w3 ,...} where δ * (q0 , wm ) = {qi , q j ,...} and there is some qk ∈ F (final state) 52
53. 53. w∈ L( M ) δ * (q0 , w) qi w q0 qk w w qk ∈ F qj 53
54. 54. Equivalence of NFAs and DFAs 54
55. 55. Equivalence of Machines For DFAs or NFAs: Machine if M1 is equivalent to machine M2 L( M 1 ) = L( M 2 ) 55
56. 56. Example L( M1 ) = {10} * L( M 2 ) = {10} * 0 q0 1 0 q0 1 NFA q1 M1 0, 1 q2 λ DFA q1 0 M2 0,1 1 q2 56
57. 57. Since L( M1 ) = L( M 2 ) = {10} * machines NFA DFA M1 M1 M2 and M2 are equivalent 0 q0 1 q1 0, 1 λ 0,1 0 q0 1 q2 q1 0 1 q2 57
58. 58. Equivalence of NFAs and DFAs Question: NFAs = DFAs ? Same power? Accept the same languages? 58
59. 59. Equivalence of NFAs and DFAs Question: NFAs = DFAs ? YES! Same power? Accept the same languages? 59
60. 60. We will prove: Languages accepted by NFAs = Languages accepted by DFAs 60
61. 61. We will prove: Languages accepted by NFAs = Languages accepted by DFAs NFAs and DFAs have the same computation power 61
62. 62. Step 1 Languages accepted by NFAs ⊇ Languages accepted by DFAs 62
63. 63. Step 1 Languages accepted by NFAs Proof: ⊇ Languages accepted by DFAs Every DFA is also an NFA 63
64. 64. Step 1 Languages accepted by NFAs Proof: ⊇ Languages accepted by DFAs Every DFA is also an NFA A language accepted by a DFA is also accepted by an NFA 64
65. 65. Step 2 Languages accepted by NFAs ⊆ Languages accepted by DFAs 65
66. 66. Step 2 Languages accepted by NFAs Proof: ⊆ Languages accepted by DFAs Any NFA can be converted to an equivalent DFA 66
67. 67. Step 2 Languages accepted by NFAs Proof: ⊆ Languages accepted by DFAs Any NFA can be converted to an equivalent DFA A language accepted by an NFA is also accepted by a DFA 67
68. 68. NFA q0 NFA to DFA a a λ q2 q1 b DFA { q0 } 68
69. 69. NFA q0 NFA to DFA a a λ q2 q1 b DFA { q0 } a { q1, q2 } 69
70. 70. NFA q0 NFA to DFA a a λ q2 q1 b DFA a { q0 } b ∅ { q1, q2 } 70
71. 71. NFA q0 NFA to DFA a a λ q2 q1 b a DFA a { q0 } b ∅ { q1, q2 } 71
72. 72. NFA q0 NFA to DFA a a λ q2 q1 b a b DFA a { q0 } b ∅ { q1, q2 } 72
73. 73. NFA q0 NFA to DFA a a λ q2 q1 b a b DFA a { q0 } { q1, q2 } ∅ a, b b 73
74. 74. NFA q0 NFA to DFA a a λ q2 q1 b a b DFA a { q0 } { q1, q2 } ∅ a, b b 74
75. 75. NFA to DFA: Remarks We are given an NFA M We want to convert it to an equivalent DFA M ′ With L( M ) = L(M ′) 75
76. 76. If the NFA has states q0 , q1, q2 ,... the DFA has states in the powerset ∅, { q0 } , { q1} , { q1, q2 } , { q3 , q4 , q7 } ,.... 76
77. 77. Procedure NFA to DFA 1. Initial state of NFA: q0 Initial state of DFA: { q0 } 77
78. 78. Example a NFA q0 a λ q1 q2 b DFA { q0 } 78
79. 79. 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 } ... Add transition ′ δ ({qi , q j ,..., qm }, a ) = {qi′ , q′j ,..., qm } 79
80. 80. Exampe a NFA q0 a q1 λ q2 b δ * (q0 , a ) = {q1, q2} DFA { q0 } a { q1, q2 } δ ( { q0 } , a ) = { q1, q2 } 80
81. 81. Procedure NFA to DFA Repeat Step 2 for all letters in alphabet, until no more transitions can be added. 81
82. 82. Example a NFA q0 a λ q1 q2 b a b DFA a { q0 } { q1, q2 } ∅ a, b b 82
83. 83. Procedure NFA to DFA 3. For any DFA state {qi , q j ,..., qm } If some qj is a final state in the NFA Then, {qi , q j ,..., qm } is a final state in the DFA 83
84. 84. Example a NFA q0 a λ q1 q2 q1 ∈ F b a b DFA a { q0 } b ∅ { q1, q2 } a, b { q1, q2 } ∈ F ′ 84
85. 85. Take NFA M Theorem Apply procedure to obtain DFA Then M and M′ M′ are equivalent : L( M ) = L( M ′) 85
86. 86. Finally We have proven Languages accepted by NFAs = Languages accepted by DFAs 86
87. 87. We have proven Languages accepted by NFAs = Languages accepted by DFAs Regular Languages 87
88. 88. We have proven Languages accepted by NFAs Regular Languages = Languages accepted by DFAs Regular Languages 88