Theory of Computation
Nondeterminism & Nondeterministic
Finite Automata (NFA), Epsilon Closure,
NFA with & w/o Epsilon Tra...
Outline
• Nondeterminism & Nondeterministic
Finite Automata (NFA)
• Epsilon Closure
• Equivalence of NFAs with & without
E...
Nondeterminism
&
Nondeterministic Finite Automata
(NFA)
http://www.vkedco.blogspot.com/
Nondeterminism
• Given an input, there can be more than
one legal sequence of steps to process
the input
• The input is ac...
Nondeterministic Example
q0 q1 q2
a,b
a a
a,b
a b
q0 {q0, q1} {q0}
q1 {q2} { }
q2 {q2} {q2}
On the input aa this NFA can
r...
Nondeterministic Example
q0 q1 q2
a,b
a a
a,b
   2100
*
,,, qqqaaq 
http://www.vkedco.blogspot.com/
Power Sets
 
        
 
         
  .ofsizetheiswhereelements,2hasgeneral,In
.3,2,1,3,...
NFA: Definition
 
    
states.acceptingofsettheis
state;starttheis
;:
symbols;ofsetfiniteai.e.alphabet,anis
states...
Instantaneous Descriptions (IDs)
 
 
     
.withendsandwithstartsthat
relationsmoreorzeroofsequenceaisthereif
on...
NFAs & Their Languages
      
    .thenNFA,anisIf
.onNFAby thereachedbecanthat
statesallofsetthe;,,|,
0
**
...
Epsilon Closure
http://www.vkedco.blogspot.com/
Spontaneous Transitions
• Unlike DFAs, NFAs are allowed to make
transitions without reading any input
symbols
• When such ...
Spontaneous Transition from q0
q0
q1
q2
ε
ε
a
b
     .
**
baML 
http://www.vkedco.blogspot.com/
Epsilon Closures
• When we deal with NFAs with ε-
transitions, we have to keep track of
where we can get to not only on sy...
Epsilon Closure Example
q0 q1 q2
0
1
2
0 1 2 ε
q0 {q0} { } { } {q1}
q1 { } {q1} { } {q2}
q2 { } { } {q2} { }
ε ε
http://ww...
Epsilon Closure Example
   
   
   
     
   
      
  
  
 .,,
closure
closur...
Equivalence of NFAs with ε-transitions
and NFAs w/o ε-transitions
• Theorem: If L is accepted by an NFA with
ε-transitions...
Epsilon Closure Example
q0 q1 q2
0
1
2
0 1 2 ε
q0 {q0} { } { } {q1}
q1 { } {q1} { } {q2}
q2 { } { } {q2} { }
ε ε
http://ww...
Epsilon Closure Example
      
      
      
      
      
      
   ...
Epsilon Closure Example
q0 q1 q2
0,1 1,2
0,1,2
0
1 2
http://www.vkedco.blogspot.com/
Practical Implication
If an NFA has ε-transitions, we can always
get rid of them before constructing an
equivalent DFA. So...
NFA vs. DFA
http://www.vkedco.blogspot.com/
Equivalence of NFAs and DFAs
• Basic insight: A DFA can keep track of the
states that the equivalent NFA may be in after
r...
Subset Construction Example
http://www.vkedco.blogspot.com/
NFA
q0 q1 q2
0,1
1 0,1
    
DFA?aNFA toisconvert thwedoHow
.1isofsymbollastnext tothe|1,0
*
xxML 
http://www.vkedc...
State q0; Input 0
If the NFA is in q0 and reads 0, it returns back to
q0. So, on 0, the DFA moves from {q0} back to
{q0}:
...
State q0; Input 1
If the NFA is in q0 and reads 1, it goes to q0 or
q1, i.e., {q0, q1}. So, on 1, the DFA moves from
{q0} ...
State {q0, q1}; Input 0
Suppose that the NFA is in one of {q0, q1} and reads 0. If
it is in q0, it goes to q0. If it is in...
State {q0, q1}; Input 1
Suppose that the NFA is in one of {q0, q1} and reads 1. If
it is in q0, it goes to q0 or q1, i.e.,...
State {q0, q2}; Input 0
Suppose that the NFA is in one of {q0, q2} and reads 0. If
it is in q0, it goes to q0. If it is in...
State {q0, q2}; Input 1
Suppose that the NFA is in one of {q0, q2} and reads 1. If it
is in q0, it goes to q0 or q1, i.e.,...
State {q0, q1, q2}; Input 0
Suppose that the NFA is in one of {q0, q1, q2} and reads 0.
If it is in q0, it will go to q0. ...
State {q0, q1, q2}; Input 1
Suppose that the NFA is in one of {q0, q1, q2} and reads
1. If it is in q0, it will go to q0 o...
DFA’s Final States
What are the final states in the new DFA? Any subset that
has a non-empty intersection with the NFA’s s...
Subset Construction Theorem
   
 
 
 
   
 
 
    .allfor,,,on,constructiBy
.|.4
;.3
;,,,,.2
;1.
whe...
NFA vs. DFA: Relative Advantages
& Disadvantages
• NFAs are simpler to write, because, in
general, they have fewer states ...
References
• A. Brooks Weber. Formal Language: A
Practical Introduction. Franklin, Beedle &
Associates.
• M. Davis, R. Sig...
Upcoming SlideShare
Loading in...5
×

Theory of Computation (Fall 2013): Nondeterminism & NFAs; Epsilon Closures; NFA vs DFA; Subset Construction

630

Published on

Published in: Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
630
On Slideshare
0
From Embeds
0
Number of Embeds
17
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Theory of Computation (Fall 2013): Nondeterminism & NFAs; Epsilon Closures; NFA vs DFA; Subset Construction

  1. 1. Theory of Computation Nondeterminism & Nondeterministic Finite Automata (NFA), Epsilon Closure, NFA with & w/o Epsilon Transitions, NFA vs. DFA, Subset Construction Vladimir Kulyukin http://www.vkedco.blogspot.com/
  2. 2. Outline • Nondeterminism & Nondeterministic Finite Automata (NFA) • Epsilon Closure • Equivalence of NFAs with & without Epsilon Transitions • NFAs vs. DFAs • Subset Construction: Equivalence of NFAs & DFAs http://www.vkedco.blogspot.com/
  3. 3. Nondeterminism & Nondeterministic Finite Automata (NFA) http://www.vkedco.blogspot.com/
  4. 4. Nondeterminism • Given an input, there can be more than one legal sequence of steps to process the input • The input is accepted if at least one legal sequence of moves ends up in an accepting state http://www.vkedco.blogspot.com/
  5. 5. Nondeterministic Example q0 q1 q2 a,b a a a,b a b q0 {q0, q1} {q0} q1 {q2} { } q2 {q2} {q2} On the input aa this NFA can reach q0, q1, and q2 http://www.vkedco.blogspot.com/
  6. 6. Nondeterministic Example q0 q1 q2 a,b a a a,b    2100 * ,,, qqqaaq  http://www.vkedco.blogspot.com/
  7. 7. Power Sets                          .ofsizetheiswhereelements,2hasgeneral,In .3,2,1,3,2,3,1,2,1,3,2,1, Then.3,2,1Let .,,,,Then.,Let :Examples . isofsetpowerTheset.abeLet SnSP SP S babaSPbaS SR|RP(S) SS n     http://www.vkedco.blogspot.com/
  8. 8. NFA: Definition        states.acceptingofsettheis state;starttheis ;: symbols;ofsetfiniteai.e.alphabet,anis states;ofsetfiniteais where,,,,,tuple-5aisNFAAn 0 0 QF Qq QPQ Q FqQMM        http://www.vkedco.blogspot.com/
  9. 9. Instantaneous Descriptions (IDs)           .withendsandwithstartsthat relationsmoreorzeroofsequenceaisthereif onlyandifi.e.IDs,onrelationais .,ifonlyandif, ,oranyandstringanyFor input.theofpartunreadtheisand statecurrenttheiswhere,,pairais NFAanforIDndescriptioousinstantaneAn ** * * JI JI aqrr,xaxq aax x Qqxq          http://www.vkedco.blogspot.com/
  10. 10. NFAs & Their Languages            .thenNFA,anisIf .onNFAby thereachedbecanthat statesallofsetthe;,,|, 0 **   F,xq|δΣxMLM x rxqrxq **   http://www.vkedco.blogspot.com/
  11. 11. Epsilon Closure http://www.vkedco.blogspot.com/
  12. 12. Spontaneous Transitions • Unlike DFAs, NFAs are allowed to make transitions without reading any input symbols • When such spontaneous transitions (aka ε–transitions) occur, the NFA is said to read ε • Remember: when a spontaneous transition occurs, the NFA may change a state without reading any input http://www.vkedco.blogspot.com/
  13. 13. Spontaneous Transition from q0 q0 q1 q2 ε ε a b      . ** baML  http://www.vkedco.blogspot.com/
  14. 14. Epsilon Closures • When we deal with NFAs with ε- transitions, we have to keep track of where we can get to not only on symbols but also on ε • ε-closure(q) = {r | there is a path from q to r consisting of only ε-transitions} http://www.vkedco.blogspot.com/
  15. 15. Epsilon Closure Example q0 q1 q2 0 1 2 0 1 2 ε q0 {q0} { } { } {q1} q1 { } {q1} { } {q2} q2 { } { } {q2} { } ε ε http://www.vkedco.blogspot.com/
  16. 16. Epsilon Closure Example                                     .,, closure closure 0,0,0,closure 0,,,closure 0,,closure0,.4 .,,,.3 .,closure.2 .,,closure.1 210 0 0 210 210 0 * 0 2100 * 211 2100 qqq q q qqq qqq qq qqqq qqq qqqq                  http://www.vkedco.blogspot.com/
  17. 17. Equivalence of NFAs with ε-transitions and NFAs w/o ε-transitions • Theorem: If L is accepted by an NFA with ε-transitions, L is accepted by an NFA without ε-transitions. • Proof: Use ε-closure to get rid of ε- transitions. http://www.vkedco.blogspot.com/
  18. 18. Epsilon Closure Example q0 q1 q2 0 1 2 0 1 2 ε q0 {q0} { } { } {q1} q1 { } {q1} { } {q2} q2 { } { } {q2} { } ε ε http://www.vkedco.blogspot.com/
  19. 19. Epsilon Closure Example                                                                .,,arestatesfinalThe .0,closure2, .1,closure1, .0,closure0, .2,closure2, .,1,closure1, .0,closure0, .2,closure2, .,1,closure1, .,,0,closure0, .fromobtainWe s.transitionthatw/ofunctioniontransitnew thedenoteLets.transitionofridgetWe 210 222 ' 22 ' 22 ' 211 ' 2111 ' 11 ' 200 ' 2100 ' 21000 ' ' ' qqq qqq qq qq qqq qqqq qq qqq qqqq qqqqq                        http://www.vkedco.blogspot.com/
  20. 20. Epsilon Closure Example q0 q1 q2 0,1 1,2 0,1,2 0 1 2 http://www.vkedco.blogspot.com/
  21. 21. Practical Implication If an NFA has ε-transitions, we can always get rid of them before constructing an equivalent DFA. So we can, without loss of generality, assume that NFAs do not contain ε-transitions. http://www.vkedco.blogspot.com/
  22. 22. NFA vs. DFA http://www.vkedco.blogspot.com/
  23. 23. Equivalence of NFAs and DFAs • Basic insight: A DFA can keep track of the states that the equivalent NFA may be in after reading each symbol of the input • Since the NFA may be in more than one state after reading a symbol, each state of the DFA must correspond to a subset of the NFA’s states • The construction of an equivalent DFA from an NFA is called subset construction http://www.vkedco.blogspot.com/
  24. 24. Subset Construction Example http://www.vkedco.blogspot.com/
  25. 25. NFA q0 q1 q2 0,1 1 0,1      DFA?aNFA toisconvert thwedoHow .1isofsymbollastnext tothe|1,0 * xxML  http://www.vkedco.blogspot.com/
  26. 26. State q0; Input 0 If the NFA is in q0 and reads 0, it returns back to q0. So, on 0, the DFA moves from {q0} back to {q0}: {q0}0 http://www.vkedco.blogspot.com/
  27. 27. State q0; Input 1 If the NFA is in q0 and reads 1, it goes to q0 or q1, i.e., {q0, q1}. So, on 1, the DFA moves from {q0} to {q0, q1}: {q0}0 {q0, q1} 1 http://www.vkedco.blogspot.com/
  28. 28. State {q0, q1}; Input 0 Suppose that the NFA is in one of {q0, q1} and reads 0. If it is in q0, it goes to q0. If it is in q1, it goes to q2. So, on 0, the DFA goes from {q0, q1} to {q0, q2}: {q0}0 {q0, q1} 1 {q0, q2} 0 http://www.vkedco.blogspot.com/
  29. 29. State {q0, q1}; Input 1 Suppose that the NFA is in one of {q0, q1} and reads 1. If it is in q0, it goes to q0 or q1, i.e., {q0, q1}. If it is in q1, it goes to q2. So, on 1, the DFA goes from {q0, q1} to {q0, q1, q2}: {q0}0 {q0, q1} 1 {q0, q2} 0 {q0, q1, q2} 1 http://www.vkedco.blogspot.com/
  30. 30. State {q0, q2}; Input 0 Suppose that the NFA is in one of {q0, q2} and reads 0. If it is in q0, it goes to q0. If it is in q2, it goes nowhere. So, on 0, the DFA from {q0, q2} goes to {q0}: {q0}0 {q0, q1} 1 {q0, q2} 0 {q0, q1, q2} 1 0 http://www.vkedco.blogspot.com/
  31. 31. State {q0, q2}; Input 1 Suppose that the NFA is in one of {q0, q2} and reads 1. If it is in q0, it goes to q0 or q1, i.e., {q0, q1}. If it is in q2, it goes nowhere. So, on 1, the DFA goes from {q0, q2} to {q0, q1}: {q0}0 {q0, q1} 1 {q0, q2} 0 {q0, q1, q2} 1 0 1 http://www.vkedco.blogspot.com/
  32. 32. State {q0, q1, q2}; Input 0 Suppose that the NFA is in one of {q0, q1, q2} and reads 0. If it is in q0, it will go to q0. If it is in q1, it will go to q2. If it is in q2, it will go nowhere. So, on 0, the DFA goes from {q0, q1, q2} to {q0, q2}: {q0}0 {q0, q1} 1 {q0, q2} 0 {q0, q1, q2} 1 0 1 0 http://www.vkedco.blogspot.com/
  33. 33. State {q0, q1, q2}; Input 1 Suppose that the NFA is in one of {q0, q1, q2} and reads 1. If it is in q0, it will go to q0 or q1, i.e., {q0, q1}. If it is in q1, it goes to q2. If it is in q2, it goes nowhere. So, on 1, the DFA goes from {q0, q1, q2} back to {q0, q1, q2}: {q0}0 {q0, q1} 1 {q0, q2} 0 {q0, q1, q2} 1 0 1 0 1 http://www.vkedco.blogspot.com/
  34. 34. DFA’s Final States What are the final states in the new DFA? Any subset that has a non-empty intersection with the NFA’s set of final states. So, the DFA has two final states: {q0, q2} and {q0, q1, q2}. {q0}0 {q0, q1} 1 {q0, q2} 0 {q0, q1, q2} 1 0 1 0 1 http://www.vkedco.blogspot.com/
  35. 35. Subset Construction Theorem                       .allfor,,,on,constructiBy .|.4 ;.3 ;,,,,.2 ;1. where,,,,DFAnewa Construct.,,,,Let:Proof .such thatDFAaisThen there ansitions.epsilon trNFA w/oabeLet:Theorem *** *          xxqxq FRQRF qq aQRaraR QPQ FqQD FqQN DLNLD N NNDD NDD ND D Rr ND ND DDDD NNNN      http://www.vkedco.blogspot.com/
  36. 36. NFA vs. DFA: Relative Advantages & Disadvantages • NFAs are simpler to write, because, in general, they have fewer states and allow for spontaneous transitions • However, they are not more powerful than DFAs, i.e. they accept the same regular languages as DFAs • For every NFA, one can construct a DFA that accepts the same language http://www.vkedco.blogspot.com/
  37. 37. References • A. Brooks Weber. Formal Language: A Practical Introduction. Franklin, Beedle & Associates. • M. Davis, R. Sigal, E. Weyuker. Computability, Complexity, & Languages: Fundamentals of Theorectical Computer Science. Academic Press. http://www.vkedco.blogspot.com/

×