SlideShare a Scribd company logo
1 of 15
Finite Automata
Finite Automata
Finite Automata are used as a model for:
◦ Software for designing digital circuits
◦ Lexical analyzer of a compiler
◦ Searching for keywords in a file or on the web.
◦ Software for verifying finite state systems, such as communication protocols.
Design of a Lexical Analyzer Generator
Translate regular expressions to NFA
Translate NFA to an efficient DFA
3
regular
expressions
NFA DFA
Simulate NFA
to recognize
tokens
Simulate DFA
to recognize
tokens
Optional
Nondeterministic Finite Automata
An NFA is a 5-tuple (S, , , s0, F) where
S is a finite set of states
 is a finite set of symbols, the alphabet
 is a mapping from S   to a set of states
s0  S is the start state
F  S is the set of accepting (or final) states
4
Transition Graph
An NFA can be diagrammatically represented by a labeled directed graph called a
transition graph
5
0
start a
1 3
2
b b
a
b
S = {0,1,2,3}
 = {a,b}
s0 = 0
F = {3}
Transition Table
The mapping  of an NFA can be represented in a transition table
6
State
Input
a
Input
b
0 {0, 1} {0}
1 {2}
2 {3}
(0,a) = {0,1}
(0,b) = {0}
(1,b) = {2}
(2,b) = {3}
The Language Defined by an NFA
An NFA accepts an input string x if and only if there is some path with edges
labeled with symbols from x in sequence from the start state to some accepting
state in the transition graph
A state transition from one state to another on the path is called a move
The language defined by an NFA is the set of input strings it accepts, such as
(ab)*abb for the example NFA
7
From Regular Expression to -NFA
(Thompson’s Construction)
8
N(r2)
N(r1)
f
i 
f
a
i
f
i
N(r1)
N(r2)
start
start
start 
 

f
i
start
N(r) f
i
start



a
r1r2
r1r2
r*  
Combining the NFAs of a Set of Regular
Expressions
9
2
a
1
start
6
a
3
start
4 5
b b
8
b
7
start
a b
a { action1 }
abb { action2 }
a*b+ { action3 }
2
a
1
6
a
3 4 5
b b
8
b
7
a b
0
start



Deterministic Finite Automata
A deterministic finite automaton is a special case of an NFA
◦ No state has an -transition
◦ For each state s and input symbol a there is at most one edge labeled a leaving
s
Each entry in the transition table is a single state
◦ At most one path exists to accept a string
◦ Simulation algorithm is simple
10
Example DFA
11
0
start a
1 3
2
b b
b
b
a
a
a
A DFA that accepts (ab)*abb
Conversion of an NFA into a DFA
The subset construction algorithm converts an NFA into a DFA using:
-closure(s) = {s}  {t  s  …  t}
-closure(T) = sT -closure(s)
move(T,a) = {t  s a t and s  T}
The algorithm produces:
Dstates is the set of states of the new DFA consisting of sets of states
of the NFA
Dtran is the transition table of the new DFA
12
-closure and move Examples
13
2
a
1
6
a
3 4 5
b b
8
b
7
a b
0
start



-closure({0}) = {0,1,3,7}
move({0,1,3,7},a) = {2,4,7}
-closure({2,4,7}) = {2,4,7}
move({2,4,7},a) = {7}
-closure({7}) = {7}
move({7},b) = {8}
-closure({8}) = {8}
move({8},a) = 
0
1
3
7
2
4
7
7 8
a b
a a none
Also used to simulate NFAs
14
Subset Construction Example 1
0
start a
1 10
2
b
b
a
b
3
4 5
6 7 8 9
 






A
start
B
C
D E
b
b
b
b
b
a
a
a
a
Dstates
A = {0,1,2,4,7}
B = {1,2,3,4,6,7,8}
C = {1,2,4,5,6,7}
D = {1,2,4,5,6,7,9}
E = {1,2,4,5,6,7,10}
a
15
Subset Construction Example 2
2
a
1
6
a
3 4 5
b b
8
b
7
a b
0
start



a1
a2
a3
Dstates
A = {0,1,3,7}
B = {2,4,7}
C = {8}
D = {7}
E = {5,8}
F = {6,8}
A
start
a
D
b
b
b
a
b
b
B
C
E F
a
b
a1
a3
a3 a2 a3

More Related Content

Similar to inbound6417574391896884649.pptx

Nondeterministic Finite Automat
Nondeterministic Finite AutomatNondeterministic Finite Automat
Nondeterministic Finite Automat
Adel Al-Ofairi
 
@vtucode.in-module-1-21CS51-5th-semester (1).pdf
@vtucode.in-module-1-21CS51-5th-semester (1).pdf@vtucode.in-module-1-21CS51-5th-semester (1).pdf
@vtucode.in-module-1-21CS51-5th-semester (1).pdf
FariyaTasneem1
 

Similar to inbound6417574391896884649.pptx (20)

Finite automata-for-lexical-analysis
Finite automata-for-lexical-analysisFinite automata-for-lexical-analysis
Finite automata-for-lexical-analysis
 
Lecture 17- F19.pdf
Lecture 17- F19.pdfLecture 17- F19.pdf
Lecture 17- F19.pdf
 
5. NFA & DFA.pdf
5. NFA & DFA.pdf5. NFA & DFA.pdf
5. NFA & DFA.pdf
 
Lex analysis
Lex analysisLex analysis
Lex analysis
 
a7f0bc7785844884c4de624f61ce5978_MIT18_404f20_lec4.pptx
a7f0bc7785844884c4de624f61ce5978_MIT18_404f20_lec4.pptxa7f0bc7785844884c4de624f61ce5978_MIT18_404f20_lec4.pptx
a7f0bc7785844884c4de624f61ce5978_MIT18_404f20_lec4.pptx
 
Lecture 1 - Lexical Analysis.ppt
Lecture 1 - Lexical Analysis.pptLecture 1 - Lexical Analysis.ppt
Lecture 1 - Lexical Analysis.ppt
 
Nondeterministic Finite Automat
Nondeterministic Finite AutomatNondeterministic Finite Automat
Nondeterministic Finite Automat
 
@vtucode.in-module-1-21CS51-5th-semester (1).pdf
@vtucode.in-module-1-21CS51-5th-semester (1).pdf@vtucode.in-module-1-21CS51-5th-semester (1).pdf
@vtucode.in-module-1-21CS51-5th-semester (1).pdf
 
03-FiniteAutomata.pptx
03-FiniteAutomata.pptx03-FiniteAutomata.pptx
03-FiniteAutomata.pptx
 
flat unit1
flat unit1flat unit1
flat unit1
 
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
 
Lexicalanalyzer
LexicalanalyzerLexicalanalyzer
Lexicalanalyzer
 
Lexicalanalyzer
LexicalanalyzerLexicalanalyzer
Lexicalanalyzer
 
Theory of automata and formal language lab manual
Theory of automata and formal language lab manualTheory of automata and formal language lab manual
Theory of automata and formal language lab manual
 
Compiler Design Material 2
Compiler Design Material 2Compiler Design Material 2
Compiler Design Material 2
 
Pcd(Mca)
Pcd(Mca)Pcd(Mca)
Pcd(Mca)
 
Pcd(Mca)
Pcd(Mca)Pcd(Mca)
Pcd(Mca)
 
PCD ?s(MCA)
PCD ?s(MCA)PCD ?s(MCA)
PCD ?s(MCA)
 
Principles of Compiler Design
Principles of Compiler DesignPrinciples of Compiler Design
Principles of Compiler Design
 
TOC_Solutions-Adi.pdf
TOC_Solutions-Adi.pdfTOC_Solutions-Adi.pdf
TOC_Solutions-Adi.pdf
 

Recently uploaded

Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 

Recently uploaded (20)

Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Air Compressor reciprocating single stage
Air Compressor reciprocating single stageAir Compressor reciprocating single stage
Air Compressor reciprocating single stage
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic Marks
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to Computers
 
Bridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptxBridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptx
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 

inbound6417574391896884649.pptx

  • 2. Finite Automata Finite Automata are used as a model for: ◦ Software for designing digital circuits ◦ Lexical analyzer of a compiler ◦ Searching for keywords in a file or on the web. ◦ Software for verifying finite state systems, such as communication protocols.
  • 3. Design of a Lexical Analyzer Generator Translate regular expressions to NFA Translate NFA to an efficient DFA 3 regular expressions NFA DFA Simulate NFA to recognize tokens Simulate DFA to recognize tokens Optional
  • 4. Nondeterministic Finite Automata An NFA is a 5-tuple (S, , , s0, F) where S is a finite set of states  is a finite set of symbols, the alphabet  is a mapping from S   to a set of states s0  S is the start state F  S is the set of accepting (or final) states 4
  • 5. Transition Graph An NFA can be diagrammatically represented by a labeled directed graph called a transition graph 5 0 start a 1 3 2 b b a b S = {0,1,2,3}  = {a,b} s0 = 0 F = {3}
  • 6. Transition Table The mapping  of an NFA can be represented in a transition table 6 State Input a Input b 0 {0, 1} {0} 1 {2} 2 {3} (0,a) = {0,1} (0,b) = {0} (1,b) = {2} (2,b) = {3}
  • 7. The Language Defined by an NFA An NFA accepts an input string x if and only if there is some path with edges labeled with symbols from x in sequence from the start state to some accepting state in the transition graph A state transition from one state to another on the path is called a move The language defined by an NFA is the set of input strings it accepts, such as (ab)*abb for the example NFA 7
  • 8. From Regular Expression to -NFA (Thompson’s Construction) 8 N(r2) N(r1) f i  f a i f i N(r1) N(r2) start start start     f i start N(r) f i start    a r1r2 r1r2 r*  
  • 9. Combining the NFAs of a Set of Regular Expressions 9 2 a 1 start 6 a 3 start 4 5 b b 8 b 7 start a b a { action1 } abb { action2 } a*b+ { action3 } 2 a 1 6 a 3 4 5 b b 8 b 7 a b 0 start   
  • 10. Deterministic Finite Automata A deterministic finite automaton is a special case of an NFA ◦ No state has an -transition ◦ For each state s and input symbol a there is at most one edge labeled a leaving s Each entry in the transition table is a single state ◦ At most one path exists to accept a string ◦ Simulation algorithm is simple 10
  • 11. Example DFA 11 0 start a 1 3 2 b b b b a a a A DFA that accepts (ab)*abb
  • 12. Conversion of an NFA into a DFA The subset construction algorithm converts an NFA into a DFA using: -closure(s) = {s}  {t  s  …  t} -closure(T) = sT -closure(s) move(T,a) = {t  s a t and s  T} The algorithm produces: Dstates is the set of states of the new DFA consisting of sets of states of the NFA Dtran is the transition table of the new DFA 12
  • 13. -closure and move Examples 13 2 a 1 6 a 3 4 5 b b 8 b 7 a b 0 start    -closure({0}) = {0,1,3,7} move({0,1,3,7},a) = {2,4,7} -closure({2,4,7}) = {2,4,7} move({2,4,7},a) = {7} -closure({7}) = {7} move({7},b) = {8} -closure({8}) = {8} move({8},a) =  0 1 3 7 2 4 7 7 8 a b a a none Also used to simulate NFAs
  • 14. 14 Subset Construction Example 1 0 start a 1 10 2 b b a b 3 4 5 6 7 8 9         A start B C D E b b b b b a a a a Dstates A = {0,1,2,4,7} B = {1,2,3,4,6,7,8} C = {1,2,4,5,6,7} D = {1,2,4,5,6,7,9} E = {1,2,4,5,6,7,10} a
  • 15. 15 Subset Construction Example 2 2 a 1 6 a 3 4 5 b b 8 b 7 a b 0 start    a1 a2 a3 Dstates A = {0,1,3,7} B = {2,4,7} C = {8} D = {7} E = {5,8} F = {6,8} A start a D b b b a b b B C E F a b a1 a3 a3 a2 a3