Upcoming SlideShare
×

# Dfa vs nfa

3,300 views

Published on

1 Comment
7 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• it is very good to understand

Are you sure you want to  Yes  No
Views
Total views
3,300
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
246
1
Likes
7
Embeds 0
No embeds

No notes for slide

### Dfa vs nfa

1. 1. Another NFA Example 0 q0 q1 0, 1 q2 1 Fall 2004 COMP 335 1
2. 2. Language accepted L(M ) = {λ, 10, 1010, 101010, ...} = {10}* 0 q0 q1 0, 1 q2 1 (redundant state) Fall 2004 COMP 335 2
3. 3. Remarks: •The  symbol never appears on the input tape •Simple automata: M1 M2 q0 q0 L(M1 ) = {} L(M 2 ) = {λ}Fall 2004 COMP 335 3
4. 4. •NFAs are interesting because we can express languages easier than DFAs NFA M1 DFA M2 a q2 q0 a q1 a q0 a q1 L( M1 ) = {a} L( M 2 ) = {a}Fall 2004 COMP 335 4
5. 5. Formal Definition of NFAs M  Q, ,  , q0 , F  Q : Set of states, i.e. q0 , q1, q2   : Input aphabet, i.e. a, b : Transition function q0 : Initial state F : Final statesFall 2004 COMP 335 5
6. 6. Transition Function   q0 , 1  q1 0 q0 q1 0, 1 q 2 1 Fall 2004 COMP 335 6
7. 7.  (q1,0)  {q0 , q2} 0 q0 q1 0, 1 q 2 1 Fall 2004 COMP 335 7
8. 8.  (q0 ,  )  {q0 , q2} 0 q0 q1 0, 1 q 2 1 Fall 2004 COMP 335 8
9. 9.  (q2 ,1)   0 q0 q1 0, 1 q 2 1 Fall 2004 COMP 335 9
10. 10. Extended Transition Function  *  * q0 , a   q1 q4 q5 a a q0 a q1 b q2  q3 Fall 2004 COMP 335 10
11. 11.  * q0 , aa   q4 , q5 q4 q5 a a q0 a q1 b q2  q3 Fall 2004 COMP 335 11
12. 12.  * q0 , ab  q2 , q3 , q0  q4 q5 a a q0 a q1 b q2  q3 Fall 2004 COMP 335 12
13. 13. Formallyq j   * qi , w : there is a walk from qi to q j with label w qi w qj w  1 2  k 1 2 k qi qjFall 2004 COMP 335 13
14. 14. 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 ) FFall 2004 COMP 335 14
15. 15. F  q0 ,q5 q4 q5 a a q0 a q1 b q2  q3  * q0 , ab   q2 , q3 , q0  ab LM  F Fall 2004 COMP 335 15
16. 16. F  q0 ,q5 q4 q5 a a q0 a q1 b q2  q3  * q0 , abaa   q4 , q5 abaa L(M ) FFall 2004 COMP 335 16
17. 17. F  q0 ,q5 q4 q5 a a q0 a q1 b q2  q3   * q0 , aba   q1 aba  LM  FFall 2004 COMP 335 17
18. 18. q4 q5 a a q0 a q1 b q2  q3  LM   ab*  {ab}*{aa}Fall 2004 COMP 335 18
19. 19. FormallyThe language accepted by NFA M is: LM   w1, w2 , w3 ,...where  * (q0 , wm )  {qi , q j ,..., qk ,}and there is some qk  F (final state)Fall 2004 COMP 335 19
20. 20. w LM   * (q0 , w) qi w q0 qk qk  F w w qjFall 2004 COMP 335 20
21. 21. NFA accept Regular LanguagesFall 2004 COMP 335 21
22. 22. Equivalence of FADefinition:An FA M1 is equivalent to FA M2if LM1   LM 2 that is if both accept the same language.Fall 2004 COMP 335 22
23. 23. Example of equivalent FA NFA M1LM1   {10} * 0 q0 q1 1 DFA M2 0,1LM 2   {10}* 0 q0 q1 1 q2 1 0Fall 2004 COMP 335 23
24. 24. We will prove:  Languages Regular accepted Languages by NFA Languages accepted by DFAThat is, NFA and DFA havethe same computation powerFall 2004 COMP 335 24
25. 25. Step 1 Languages accepted  Regular Languages by NFA Proof: Every DFA is trivially an NFA Any language L accepted by a DFA is also accepted by an NFAFall 2004 COMP 335 25
26. 26. Step 2 Languages accepted  Regular Languages by NFA Proof: Any NFA can be converted into an equivalent DFA Any language accepted by an NFA is also accepted by a DFAFall 2004 COMP 335 26
27. 27. Convert NFA to DFANFA M a q a q 0  q 1 2 bDFA M q0 Fall 2004 COMP 335 27
28. 28. Convert NFA to DFANFA M a q a q 0  q 1 2 bDFA M q0  a q1, q2 Fall 2004 COMP 335 28
29. 29. Convert NFA to DFANFA M a q a q 0  q 1 2 bDFA M q0  a q1, q2  b Fall 2004 COMP 335 29
30. 30. Convert NFA to DFANFA M a q a q 0  q 1 2 b aDFA M q0  a q1, q2  b Fall 2004 COMP 335 30
31. 31. Convert NFA to DFANFA M a q a q 0  q 1 2 b aDFA M b q0  a q1, q2  b Fall 2004 COMP 335 31
32. 32. Convert NFA to DFANFA M a q a q 0  q 1 2 b aDFA M b q0  a q1, q2  b  a, bFall 2004 COMP 335 32
33. 33. Convert NFA to DFANFA M a q a q 0  q 1 2 LM   L(M ) b aDFA M b q0  a q1, q2  b  a, bFall 2004 COMP 335 33
34. 34. NFA to DFA: RemarksWe are given an NFA MWe want to convert itinto an equivalent DFA MThat is, LM   L(M )Fall 2004 COMP 335 34
35. 35. If the NFA has states q0 , q1, q2 ,...Then the DFA has states in the powerset , q0 , q1, q1 , q2 ,....Fall 2004 COMP 335 35
36. 36. Procedure NFA to DFA1. Initial state of NFA: q0 Initial state of DFA: q0 Fall 2004 COMP 335 36
37. 37. ExampleNFA M a q0 a q1  q2 bDFA M q0 Fall 2004 COMP 335 37
38. 38. 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 the following transition to the DFA  {qi , q j ,..., qm}, a   {qi , qj ,..., qm} Fall 2004 COMP 335 38
39. 39. ExampleNFA M a q0 a q1  q2 b  * (q0 , a )  {q1, q2 } DFA M q0  a q1, q2   q0 , a   q1, q2 Fall 2004 COMP 335 39
40. 40. Procedure NFA to DFARepeat step 2 for all symbols in the alphabet ∑, until no more transitions can be added.Fall 2004 COMP 335 40
41. 41. ExampleNFA M a q0 a q1  q2 b aDFA M b q0  a q1, q2  b  a, bFall 2004 COMP 335 41
42. 42. 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 DFAFall 2004 COMP 335 42
43. 43. ExampleNFA M a q0 a q1  q2 q1  F b aDFA M b q0  a q1, q2  b q1, q2  F   a, bFall 2004 COMP 335 43
44. 44. Theorem Take NFA MApply the procedure to obtain DFA M Then, M and M  are equivalent: LM   LM Fall 2004 COMP 335 44
45. 45. Proof LM   LM  L  M   L M   AND L  M   L M  Fall 2004 COMP 335 45
46. 46. First we show: L  M   L M   Take arbitrary string : w L (M ) We will prove: w  L(M )Fall 2004 COMP 335 46
47. 47. w L(M )M: q0 w qf w  1 2  k 1 2 k M: q0 qfFall 2004 COMP 335 47
48. 48. We will show that if w L(M ) w  1 2  k 1 2 k M: q0 qf 1 2 k M: {q0} {q f ,} w  L(M )Fall 2004 COMP 335 48
49. 49. More generally, we will show that if in M: (arbitrary string) v  a1a2 an a1 a2 an M: q0 qi qj ql qm M: a1 a2 an {q0} {qi ,} {q j ,} {ql ,} {qm ,}Fall 2004 COMP 335 49
50. 50. Proof by induction on |v| The basis case: v  a1 a1 M: q0 qi M: a1 {q0} {qi ,}Fall 2004 COMP 335 50
51. 51. Induction hypothesis: 1 | v | k v  a1a2 ak a1 a2 ak M: q0 qi qj qc qd M: a1 a2 ak {q0} {qi ,} {q j ,} {qc ,} {qd ,}Fall 2004 COMP 335 51
52. 52. Induction Step: | v | k  1 v  a1a2 ak ak 1  vak 1     v a1 a2 ak M: q0 qi qj qc qd v M: a1 a2 ak {q0} {qi ,} {q j ,} {qc ,} {qd ,}Fall 2004 v COMP 335 52
53. 53. Induction Step: | v | k  1 v  a1a2 ak ak 1  vak 1     v a1 a2 ak ak 1 M: q0 qi qj qc qd qe v M: a1 a2 ak ak 1 {q0} {qi ,} {q j ,} {qc ,} {qd ,} {qe ,}Fall 2004 v COMP 335 53
54. 54. Therefore if w L(M ) w  1 2  k 1 2 k M: q0 qf 1 2 k M: {q0} {q f ,} w  L(M )Fall 2004 COMP 335 54
55. 55. We have shown: L  M   L M   We also need to show: L  M   L M   (proof is similar)Fall 2004 COMP 335 55