Dfa vs nfa
Upcoming SlideShare
Loading in...5
×
 

Dfa vs nfa

on

  • 1,597 views

 

Statistics

Views

Total Views
1,597
Views on SlideShare
1,597
Embed Views
0

Actions

Likes
0
Downloads
56
Comments
1

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • it is very good to understand
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Dfa vs nfa Dfa vs nfa Presentation Transcript

  • Another NFA Example 0 q0 q1 0, 1 q2 1 Fall 2004 COMP 335 1
  • Language accepted L(M ) = {λ, 10, 1010, 101010, ...} = {10}* 0 q0 q1 0, 1 q2 1 (redundant state) Fall 2004 COMP 335 2
  • 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 View slide
  • •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 View slide
  • 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
  • Transition Function   q0 , 1  q1 0 q0 q1 0, 1 q 2 1 Fall 2004 COMP 335 6
  •  (q1,0)  {q0 , q2} 0 q0 q1 0, 1 q 2 1 Fall 2004 COMP 335 7
  •  (q0 ,  )  {q0 , q2} 0 q0 q1 0, 1 q 2 1 Fall 2004 COMP 335 8
  •  (q2 ,1)   0 q0 q1 0, 1 q 2 1 Fall 2004 COMP 335 9
  • Extended Transition Function  *  * q0 , a   q1 q4 q5 a a q0 a q1 b q2  q3 Fall 2004 COMP 335 10
  •  * q0 , aa   q4 , q5 q4 q5 a a q0 a q1 b q2  q3 Fall 2004 COMP 335 11
  •  * q0 , ab  q2 , q3 , q0  q4 q5 a a q0 a q1 b q2  q3 Fall 2004 COMP 335 12
  • 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
  • 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
  • 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
  • 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
  • F  q0 ,q5 q4 q5 a a q0 a q1 b q2  q3   * q0 , aba   q1 aba  LM  FFall 2004 COMP 335 17
  • q4 q5 a a q0 a q1 b q2  q3  LM   ab*  {ab}*{aa}Fall 2004 COMP 335 18
  • 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
  • w LM   * (q0 , w) qi w q0 qk qk  F w w qjFall 2004 COMP 335 20
  • NFA accept Regular LanguagesFall 2004 COMP 335 21
  • 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
  • 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
  • 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
  • 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
  • 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
  • Convert NFA to DFANFA M a q a q 0  q 1 2 bDFA M q0 Fall 2004 COMP 335 27
  • Convert NFA to DFANFA M a q a q 0  q 1 2 bDFA M q0  a q1, q2 Fall 2004 COMP 335 28
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • Procedure NFA to DFA1. Initial state of NFA: q0 Initial state of DFA: q0 Fall 2004 COMP 335 36
  • ExampleNFA M a q0 a q1  q2 bDFA M q0 Fall 2004 COMP 335 37
  • 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
  • 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
  • Procedure NFA to DFARepeat step 2 for all symbols in the alphabet ∑, until no more transitions can be added.Fall 2004 COMP 335 40
  • ExampleNFA M a q0 a q1  q2 b aDFA M b q0  a q1, q2  b  a, bFall 2004 COMP 335 41
  • 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
  • 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
  • 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
  • Proof LM   LM  L  M   L M   AND L  M   L M  Fall 2004 COMP 335 45
  • First we show: L  M   L M   Take arbitrary string : w L (M ) We will prove: w  L(M )Fall 2004 COMP 335 46
  • w L(M )M: q0 w qf w  1 2  k 1 2 k M: q0 qfFall 2004 COMP 335 47
  • 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
  • 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
  • Proof by induction on |v| The basis case: v  a1 a1 M: q0 qi M: a1 {q0} {qi ,}Fall 2004 COMP 335 50
  • 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
  • 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
  • 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
  • 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
  • We have shown: L  M   L M   We also need to show: L  M   L M   (proof is similar)Fall 2004 COMP 335 55