SlideShare a Scribd company logo
1 of 11
 
Compiler conversion of regular expression regular expression NFA NFA DFA DFA DFA MIN by Thompson's construction by subset construction by minimisation algorithm input parser
Deterministic Computation Non-Deterministic Computation accept or reject accept reject
Formal Definition of NFAs Set of states,  i.e. Input aphabet, i.e. Transition function Initial state Final states
 
Nondeterministic Automata vs Deterministic Automata We learned that NFA is a convenient model for showing the relationships among regular grammars, FA, and regular expressions, and designing them.  However, we know that an NFA is a conceptual model that cannot  directly be built because of the nondeterministic transition. Then what about all the NFA that appear in the examples and proofs? Are those nondeterministic automata remain as theoretical model that cannot bring down to the real world? For context-free languages, there are languages that can only be recognized by NPDA, for example {xx R  | x  {a, b} *  }. As far as PDA are concerned, NPDA are strictly more powerful than DPDA. For LBA, it is open problem. (Looks like the space restriction is too much for a DLBA to do the same computation as an NLBA does.) For TM, any problem that can be solved by an NTM can also be solved by a DTM by tracing every possible transition of an NTM computation using its unlimited space available.
Fortunately, for NFA there is a straightforward way to transform them into DFA. (Actually it is based on the same idea that we used to eliminate   -transitions.) The basic idea is to consider the set of states that can be reachable by a transition as a single state in deterministic transition. The following example will be enough to understand the technique. (We assume that the automaton has no   -transitions.)  Notice that the state with label {0, 1, 2} is from the set of states given by the nondeterministic transition   (0, a) = {0, 1, 2}. Also notice that any state whose label contains an accepting state is defined as an accepting state in the deterministic machine. b a,b,c (a) An NFA a 1 2 a 0 b,c c start {0,1,2} {2} a a {1,2} b c b c c (b) Converted DFA 0 start b,c
Minimization Technique for DFA The number of states of an automaton has direct affect to the size of the machine realizing the automaton. Hence, it is very important to reduce the number of states, if possible. For PDA, LBA and TM, it is very difficult problem to reduce the number of states. However, for DFA there is very efficient algorithm for minimizing the number of states of a given DFA.  Figure (a) below is a part of the state transition graph of a DFA  M = ( Q ,    ,    , q 0 , F ), where    = { a, b }. Clearly, for every w        * ,   ( q 3  , w ) is in an accepting state if and only if   ( q 4  , w )   is. Hence, we can merge q 3  and q 4  into a single state as shown in Figure (b) without affecting the language of the machine. b a a b b a a a b q 4 b q 3 q 1 q 2 Figure (a) q 34 q 1 q 2 Figure (b) b
State Reduction by Partitioning We say two states  p  and   q  are  equivalent  (or indistinguishable), if, for every string w        *  , transition   (  p   , w )   ends in an accepting state if and only if   (  q   , w) does. In the preceding slide states q 3  and   q 4  are equivalent.  There are efficient algorithms available for  computing the sets of equivalent states of a given DFA.  The following example shows a procedure using the set partitioning technique. The technique is similar to one that they use for partitioning people into groups (each having certain preferences) based on their responses to questionnaire. The following two slides show the detailed steps for computing equivalent state sets of the DFA in Figure (a) and constructing the reduced DFA shown in Figure (b). b b a b b a a b a b a 4 3 1 2 a 5 0 Figure (a)  A DFA b a a, b 3 1,2 a b 4,5 0 a, b Figure (b) Reduced DFA
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],State Reduction by Partitioning(cont’ed)
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

More Related Content

What's hot

What's hot (20)

Introduction TO Finite Automata
Introduction TO Finite AutomataIntroduction TO Finite Automata
Introduction TO Finite Automata
 
Chomsky classification of Language
Chomsky classification of LanguageChomsky classification of Language
Chomsky classification of Language
 
Minimization of DFA
Minimization of DFAMinimization of DFA
Minimization of DFA
 
NFA and DFA
NFA and DFANFA and DFA
NFA and DFA
 
simple problem to convert NFA with epsilon to without epsilon
simple problem to convert NFA with epsilon to without epsilonsimple problem to convert NFA with epsilon to without epsilon
simple problem to convert NFA with epsilon to without epsilon
 
Multi Head, Multi Tape Turing Machine
Multi Head, Multi Tape Turing MachineMulti Head, Multi Tape Turing Machine
Multi Head, Multi Tape Turing Machine
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
1.7. eqivalence of nfa and dfa
1.7. eqivalence of nfa and dfa1.7. eqivalence of nfa and dfa
1.7. eqivalence of nfa and dfa
 
NFA & DFA
NFA & DFANFA & DFA
NFA & DFA
 
Kleene's theorem
Kleene's theoremKleene's theorem
Kleene's theorem
 
Lex
LexLex
Lex
 
Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
 
Minimization of DFA.pptx
Minimization of DFA.pptxMinimization of DFA.pptx
Minimization of DFA.pptx
 
Mealy and moore machine
Mealy and moore machineMealy and moore machine
Mealy and moore machine
 
Turing machine-TOC
Turing machine-TOCTuring machine-TOC
Turing machine-TOC
 
Deciability (automata presentation)
Deciability (automata presentation)Deciability (automata presentation)
Deciability (automata presentation)
 
Graphs
GraphsGraphs
Graphs
 
Syntax directed translation
Syntax directed translationSyntax directed translation
Syntax directed translation
 
FInite Automata
FInite AutomataFInite Automata
FInite Automata
 
Lexical analyzer generator lex
Lexical analyzer generator lexLexical analyzer generator lex
Lexical analyzer generator lex
 

Viewers also liked

Intermediate code- generation
Intermediate code- generationIntermediate code- generation
Intermediate code- generation
rawan_z
 

Viewers also liked (18)

Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
 
Dfa vs nfa
Dfa vs nfaDfa vs nfa
Dfa vs nfa
 
Optimization of dfa
Optimization of dfaOptimization of dfa
Optimization of dfa
 
Lexical Analysis
Lexical AnalysisLexical Analysis
Lexical Analysis
 
Bottom - Up Parsing
Bottom - Up ParsingBottom - Up Parsing
Bottom - Up Parsing
 
DFA Minimization
DFA MinimizationDFA Minimization
DFA Minimization
 
optimization of DFA
optimization of DFAoptimization of DFA
optimization of DFA
 
Programming languages,compiler,interpreter,softwares
Programming languages,compiler,interpreter,softwaresProgramming languages,compiler,interpreter,softwares
Programming languages,compiler,interpreter,softwares
 
Programming Languages / Translators
Programming Languages / TranslatorsProgramming Languages / Translators
Programming Languages / Translators
 
Compiler Chapter 1
Compiler Chapter 1Compiler Chapter 1
Compiler Chapter 1
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
Intermediate code- generation
Intermediate code- generationIntermediate code- generation
Intermediate code- generation
 
Translators(Compiler, Assembler) and interpreter
Translators(Compiler, Assembler) and interpreterTranslators(Compiler, Assembler) and interpreter
Translators(Compiler, Assembler) and interpreter
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generation
 
Language translator
Language translatorLanguage translator
Language translator
 
Lexical analyzer
Lexical analyzerLexical analyzer
Lexical analyzer
 
Lexical analyzer
Lexical analyzerLexical analyzer
Lexical analyzer
 
Code generation
Code generationCode generation
Code generation
 

Similar to Nfa vs dfa

4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...
4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...
4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...
venkatapranaykumarGa
 
Chapter 2 2 1 2
Chapter 2 2 1 2Chapter 2 2 1 2
Chapter 2 2 1 2
bolovv
 

Similar to Nfa vs dfa (20)

CS 162 Fall 2015 Homework 1 Problems September 29, 2015 Timothy Johnson 1. Ex...
CS 162 Fall 2015 Homework 1 Problems September 29, 2015 Timothy Johnson 1. Ex...CS 162 Fall 2015 Homework 1 Problems September 29, 2015 Timothy Johnson 1. Ex...
CS 162 Fall 2015 Homework 1 Problems September 29, 2015 Timothy Johnson 1. Ex...
 
Hwsoln03 toc
Hwsoln03 tocHwsoln03 toc
Hwsoln03 toc
 
Lecture 17- F19.pdf
Lecture 17- F19.pdfLecture 17- F19.pdf
Lecture 17- F19.pdf
 
4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...
4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...
4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...
 
Chapter 2 limits of DFA NDFA.ppt
Chapter 2  limits of DFA  NDFA.pptChapter 2  limits of DFA  NDFA.ppt
Chapter 2 limits of DFA NDFA.ppt
 
DFA_Minimization_Presentation_uploaded.pdf
DFA_Minimization_Presentation_uploaded.pdfDFA_Minimization_Presentation_uploaded.pdf
DFA_Minimization_Presentation_uploaded.pdf
 
DFA_Minimization for engineering students.ppt
DFA_Minimization for engineering students.pptDFA_Minimization for engineering students.ppt
DFA_Minimization for engineering students.ppt
 
Nondeterministic Finite Automata AFN.pdf
Nondeterministic Finite Automata AFN.pdfNondeterministic Finite Automata AFN.pdf
Nondeterministic Finite Automata AFN.pdf
 
Automata theory
Automata theoryAutomata theory
Automata theory
 
1.3.1 deterministic finite automaton
1.3.1 deterministic finite automaton1.3.1 deterministic finite automaton
1.3.1 deterministic finite automaton
 
Lec1.pptx
Lec1.pptxLec1.pptx
Lec1.pptx
 
flat unit1
flat unit1flat unit1
flat unit1
 
Theory of Computation FSM Conversions and Problems
Theory of Computation FSM Conversions and ProblemsTheory of Computation FSM Conversions and Problems
Theory of Computation FSM Conversions and Problems
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
 
Automata theory - RE to DFA Conversion
Automata theory - RE to DFA ConversionAutomata theory - RE to DFA Conversion
Automata theory - RE to DFA Conversion
 
Chapter 2 2 1 2
Chapter 2 2 1 2Chapter 2 2 1 2
Chapter 2 2 1 2
 
NFA Converted to DFA , Minimization of DFA , Transition Diagram
NFA Converted to DFA , Minimization of DFA , Transition DiagramNFA Converted to DFA , Minimization of DFA , Transition Diagram
NFA Converted to DFA , Minimization of DFA , Transition Diagram
 
Lecture 03 lexical analysis
Lecture 03 lexical analysisLecture 03 lexical analysis
Lecture 03 lexical analysis
 
TOC_Solutions-Adi.pdf
TOC_Solutions-Adi.pdfTOC_Solutions-Adi.pdf
TOC_Solutions-Adi.pdf
 
TOC Solutions-Adi.pdf
TOC Solutions-Adi.pdfTOC Solutions-Adi.pdf
TOC Solutions-Adi.pdf
 

Nfa vs dfa

  • 1.  
  • 2. Compiler conversion of regular expression regular expression NFA NFA DFA DFA DFA MIN by Thompson's construction by subset construction by minimisation algorithm input parser
  • 3. Deterministic Computation Non-Deterministic Computation accept or reject accept reject
  • 4. Formal Definition of NFAs Set of states, i.e. Input aphabet, i.e. Transition function Initial state Final states
  • 5.  
  • 6. Nondeterministic Automata vs Deterministic Automata We learned that NFA is a convenient model for showing the relationships among regular grammars, FA, and regular expressions, and designing them. However, we know that an NFA is a conceptual model that cannot directly be built because of the nondeterministic transition. Then what about all the NFA that appear in the examples and proofs? Are those nondeterministic automata remain as theoretical model that cannot bring down to the real world? For context-free languages, there are languages that can only be recognized by NPDA, for example {xx R | x  {a, b} * }. As far as PDA are concerned, NPDA are strictly more powerful than DPDA. For LBA, it is open problem. (Looks like the space restriction is too much for a DLBA to do the same computation as an NLBA does.) For TM, any problem that can be solved by an NTM can also be solved by a DTM by tracing every possible transition of an NTM computation using its unlimited space available.
  • 7. Fortunately, for NFA there is a straightforward way to transform them into DFA. (Actually it is based on the same idea that we used to eliminate  -transitions.) The basic idea is to consider the set of states that can be reachable by a transition as a single state in deterministic transition. The following example will be enough to understand the technique. (We assume that the automaton has no  -transitions.) Notice that the state with label {0, 1, 2} is from the set of states given by the nondeterministic transition  (0, a) = {0, 1, 2}. Also notice that any state whose label contains an accepting state is defined as an accepting state in the deterministic machine. b a,b,c (a) An NFA a 1 2 a 0 b,c c start {0,1,2} {2} a a {1,2} b c b c c (b) Converted DFA 0 start b,c
  • 8. Minimization Technique for DFA The number of states of an automaton has direct affect to the size of the machine realizing the automaton. Hence, it is very important to reduce the number of states, if possible. For PDA, LBA and TM, it is very difficult problem to reduce the number of states. However, for DFA there is very efficient algorithm for minimizing the number of states of a given DFA. Figure (a) below is a part of the state transition graph of a DFA M = ( Q ,  ,  , q 0 , F ), where  = { a, b }. Clearly, for every w   * ,  ( q 3 , w ) is in an accepting state if and only if  ( q 4 , w ) is. Hence, we can merge q 3 and q 4 into a single state as shown in Figure (b) without affecting the language of the machine. b a a b b a a a b q 4 b q 3 q 1 q 2 Figure (a) q 34 q 1 q 2 Figure (b) b
  • 9. State Reduction by Partitioning We say two states p and q are equivalent (or indistinguishable), if, for every string w   * , transition  ( p , w ) ends in an accepting state if and only if  ( q , w) does. In the preceding slide states q 3 and q 4 are equivalent. There are efficient algorithms available for computing the sets of equivalent states of a given DFA. The following example shows a procedure using the set partitioning technique. The technique is similar to one that they use for partitioning people into groups (each having certain preferences) based on their responses to questionnaire. The following two slides show the detailed steps for computing equivalent state sets of the DFA in Figure (a) and constructing the reduced DFA shown in Figure (b). b b a b b a a b a b a 4 3 1 2 a 5 0 Figure (a) A DFA b a a, b 3 1,2 a b 4,5 0 a, b Figure (b) Reduced DFA
  • 10.
  • 11.