SlideShare a Scribd company logo
1 of 23
1
FINITE AUTOMATA
NFA
2
Finite Automata
• Recognizer for a language
– takes an input string & determines whether it’s a
valid sentence of the language
• Non Deterministic
– Has more than one alternative action for the same
input symbol
• Deterministic
– Has at most one action for a given input symbol
3
Finite Automata
• Non-Deterministic Finite Automata (NFAs) easily
represent regular expression, slower
• Deterministic Finite Automata (DFAs) require
more complexity to represent regular
expressions, faster
4
Non Deterministic Finite
Automata
• An NFA is a mathematical model that consists of
:
– S, a set of states
– , the symbols of the input alphabet
– move, a transition function.
• move(state, symbol)  set of states
• move : S  {}  S
– A state, s0  S, the start state
– F  S, a set of final or accepting states.
5
Representation of NFAs
• Transition diagrams
– 2 edges on same input
–  edges are permitted
• Transition tables
– Suitable for program implementations
– Takes up a lot of space when the input alphabet is
large
– Provides fast access
– Adjacency list representation – compact but slow
6
Example (a/b)*abb
S = { 0, 1, 2, 3 }
s0 = 0
F = { 3 }
 = { a, b }
start
0 3
b
2
1 b
a
a
b
s
t
a
t
e
i n p u t
0
1
2
a b
{ 0, 1 }
-- { 2 }
-- { 3 }
{ 0 }
 (null) moves possible
j
i 
Switch state but do not
use any input symbol
7
NFA
• An NFA accepts a string x iff there is some
path in the transition graph from the start
state to some accepting state such that the
edge labels along the path spell out x.
• Can add dead state to handle all undefined
transitions
8
Example (Contd.)
start
0 3
b
2
1 b
a
a
b Given an input string, we trace moves
If no more input & in final state, ACCEPT
EXAMPLE:
Input: ababb
move(0, a) = 1
move(1, b) = 2
move(2, a) = ? (undefined)
REJECT !
move(0, a) = 0
move(0, b) = 0
move(0, a) = 1
move(1, b) = 2
move(2, b) = 3
ACCEPT !
9
Constructing an NFA from a RE
• Syntax directed construction procedure
• Each step of the construction process
introduces at most two new states
• Resulting NFA has at most 2 x No. of
symbols and operators- states
10
Thompson’s Construction Algorithm
• Input: A regular expression r over an
alphabet
• Output: An NFA N accepting L(r)
– First r is parsed into its constituent sub-
expressions
– Then NFA is constructed for each of the basic
symbols
– If same symbol occurs repeatedly, separate
NFA is constructed for each occurrence
11
Thompson’s Construction Algorithm
2. For a   in the regular expression, construct NFA
a
start i f L(a)
1. For  in the regular expression, construct NFA
L()

start i f
12
Thompson’s Construction Algorithm
where i and f are new start / final states, and -moves
are introduced from i to the old start states of N(s) and
N(t) as well as from all of their final states to f.
3(a) If s, t are regular expressions, N(s), N(t) their NFAs
s|t has NFA:

i f

N(s)
N(t) 

L(s)  L(t)
13
Thompson’s Construction Algorithm
3.(b) If s, t are regular expressions, N(s), N(t) their NFAs
st (concatenation) has NFA:
start
i f
N(s) N(t) L(s) L(t)
Alternative:
overlap
N(s)

start i f
N(t) 

where i is the start state of N(s) (or new under the
alternative) and f is the final state of N(t) (or new).
Overlap maps final states of N(s) to start state of N(t).
14
Thompson’s Construction Algorithm
f
N(s)

start i 


where : i is new start state and f is new final state
-move i to f (to accept null string)
-moves i to old start, old final(s) to f
-move old final to old start
3.(c) If s is a regular expressions, N(s) its NFA, s*
(Kleene star) has NFA:
15
Properties of Construction
Let r be a regular expression, with NFA N(r), then
• N(r) has #of states  2*(#symbols +
#operators) of r
• N(r) has exactly one start and one accepting
state
• Each state of N(r) has at most one outgoing
edge a or at most two outgoing ’s
• Unique names should be assigned to all states
16
NFA Construction Example
r13
r12
r5
r3 r11
r4
r9
r10
r8
r7
r6
r0
r1 r2
b
*
c
a a
|
( )
b
|
*
c
Example - ab*c | a(b|c*)
Parse Tree for this regular expression:
17
NFA Construction Example
r3: a
r0: b
r2: c
b 



r1:
r4 : r1 r2
b 


 c
r5 : r3 r4
b 



a c
18
NFA Construction Example
r11: a
r7: b
r6: c
c 



r9 : r7 | r8


b
c 



r8:
c 



r12 : r11 r10


b
a
r10 : r9
19
NFA Construction Example
r13 : r5 | r12
b 



a c
c 





b
a




1
6
5
4
3
8
2
10
9 12 13 14
11
15
7
16
17
20
Simulation of an NFA
• Given an NFA N constructed by Thompson’s
Algorithm and an input string x – determine whether
N accepts x
• Algorithm reads input one character at a time and
computes set of states N could be in after having
read each prefix
• Runs in time |N| x |x|
21
Simulation of an NFA
ε-closure(T)
push all states in T onto stack
initialize ε-closure(T) to T
while stack is not empty
pop t from top of stack
for each state u with an ε-transition from t
if u is not in ε-closure(T) then
add u to ε-closure(T)
push u onto stack
22
Simulation of an NFA
• Input: NFA and input string x
• Output: Yes/ No
• Similar to Subset construction procedure; Computes ε-
closure(move(S,a))
S  -closure({s0})
c  nextchar;
while c  eof do
S  -closure(move(S,c));
c  nextchar;
end;
if SF then return “yes” else return “no”
23
Simulation of an NFA
• Two Stacks and bit vector implementation
of states can be used
– Stack 1 – keeps track of current set of states
– Stack 2 – To compute next set
– Roles of both stacks can be interchanged

More Related Content

What's hot

Fundamental principle of counting- ch 6 - Discrete Mathematics
Fundamental principle of counting- ch 6 - Discrete MathematicsFundamental principle of counting- ch 6 - Discrete Mathematics
Fundamental principle of counting- ch 6 - Discrete MathematicsOmnia A. Abdullah
 
Graph Theory: Planarity & Dual Graph
Graph Theory: Planarity & Dual GraphGraph Theory: Planarity & Dual Graph
Graph Theory: Planarity & Dual GraphAshikur Rahman
 
Single source stortest path bellman ford and dijkstra
Single source stortest path bellman ford and dijkstraSingle source stortest path bellman ford and dijkstra
Single source stortest path bellman ford and dijkstraRoshan Tailor
 
Algorithms Lecture 3: Analysis of Algorithms II
Algorithms Lecture 3: Analysis of Algorithms IIAlgorithms Lecture 3: Analysis of Algorithms II
Algorithms Lecture 3: Analysis of Algorithms IIMohamed Loey
 
POST’s CORRESPONDENCE PROBLEM
POST’s CORRESPONDENCE PROBLEMPOST’s CORRESPONDENCE PROBLEM
POST’s CORRESPONDENCE PROBLEMRajendran
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programmingShakil Ahmed
 
Slides Chapter10.1 10.2
Slides Chapter10.1 10.2Slides Chapter10.1 10.2
Slides Chapter10.1 10.2showslidedump
 
Informed search algorithms.pptx
Informed search algorithms.pptxInformed search algorithms.pptx
Informed search algorithms.pptxDr.Shweta
 
Logic and proof
Logic and proofLogic and proof
Logic and proofSuresh Ram
 
Pushdown Automata Theory
Pushdown Automata TheoryPushdown Automata Theory
Pushdown Automata TheorySaifur Rahman
 

What's hot (20)

SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS
 
4.1 turing machines
4.1 turing machines4.1 turing machines
4.1 turing machines
 
Fundamental principle of counting- ch 6 - Discrete Mathematics
Fundamental principle of counting- ch 6 - Discrete MathematicsFundamental principle of counting- ch 6 - Discrete Mathematics
Fundamental principle of counting- ch 6 - Discrete Mathematics
 
Power series
Power seriesPower series
Power series
 
Graph Theory: Planarity & Dual Graph
Graph Theory: Planarity & Dual GraphGraph Theory: Planarity & Dual Graph
Graph Theory: Planarity & Dual Graph
 
Red Black Tree Insertion & Deletion
Red Black Tree Insertion & DeletionRed Black Tree Insertion & Deletion
Red Black Tree Insertion & Deletion
 
Single source stortest path bellman ford and dijkstra
Single source stortest path bellman ford and dijkstraSingle source stortest path bellman ford and dijkstra
Single source stortest path bellman ford and dijkstra
 
Algorithms Lecture 3: Analysis of Algorithms II
Algorithms Lecture 3: Analysis of Algorithms IIAlgorithms Lecture 3: Analysis of Algorithms II
Algorithms Lecture 3: Analysis of Algorithms II
 
POST’s CORRESPONDENCE PROBLEM
POST’s CORRESPONDENCE PROBLEMPOST’s CORRESPONDENCE PROBLEM
POST’s CORRESPONDENCE PROBLEM
 
pushdown automata
pushdown automatapushdown automata
pushdown automata
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
Latches and flip flops
Latches and flip flopsLatches and flip flops
Latches and flip flops
 
Geometric algorithms
Geometric algorithmsGeometric algorithms
Geometric algorithms
 
Slides Chapter10.1 10.2
Slides Chapter10.1 10.2Slides Chapter10.1 10.2
Slides Chapter10.1 10.2
 
Informed search algorithms.pptx
Informed search algorithms.pptxInformed search algorithms.pptx
Informed search algorithms.pptx
 
K - Map
  K - Map    K - Map
K - Map
 
Logic and proof
Logic and proofLogic and proof
Logic and proof
 
Unit 4 queue
Unit   4 queueUnit   4 queue
Unit 4 queue
 
Graph coloring
Graph coloringGraph coloring
Graph coloring
 
Pushdown Automata Theory
Pushdown Automata TheoryPushdown Automata Theory
Pushdown Automata Theory
 

Similar to 2_4 Finite Automata.ppt

Similar to 2_4 Finite Automata.ppt (20)

inbound6417574391896884649.pptx
inbound6417574391896884649.pptxinbound6417574391896884649.pptx
inbound6417574391896884649.pptx
 
Implementation of lexical analyser
Implementation of lexical analyserImplementation of lexical analyser
Implementation of lexical analyser
 
Finite automata-for-lexical-analysis
Finite automata-for-lexical-analysisFinite automata-for-lexical-analysis
Finite automata-for-lexical-analysis
 
03-FiniteAutomata.pptx
03-FiniteAutomata.pptx03-FiniteAutomata.pptx
03-FiniteAutomata.pptx
 
Ch3.ppt
Ch3.pptCh3.ppt
Ch3.ppt
 
Regular Expression to Finite Automata
Regular Expression to Finite AutomataRegular Expression to Finite Automata
Regular Expression to Finite Automata
 
Lecture4 lexical analysis2
Lecture4 lexical analysis2Lecture4 lexical analysis2
Lecture4 lexical analysis2
 
Theory of computation and automata
Theory of computation and automataTheory of computation and automata
Theory of computation and automata
 
Theory of computation and automata
Theory of computation and automataTheory of computation and automata
Theory of computation and automata
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
 
TOC Introduction
TOC Introduction TOC Introduction
TOC Introduction
 
1. finite_automata_new.ppt
1. finite_automata_new.ppt1. finite_automata_new.ppt
1. finite_automata_new.ppt
 
Lec1.pptx
Lec1.pptxLec1.pptx
Lec1.pptx
 
Nondeterministic Finite Automat
Nondeterministic Finite AutomatNondeterministic Finite Automat
Nondeterministic Finite Automat
 
Automata
AutomataAutomata
Automata
 
SS UI Lecture 5
SS UI Lecture 5SS UI Lecture 5
SS UI Lecture 5
 
@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
 
Unit2 Toc.pptx
Unit2 Toc.pptxUnit2 Toc.pptx
Unit2 Toc.pptx
 
Lexicalanalyzer
LexicalanalyzerLexicalanalyzer
Lexicalanalyzer
 
Lexicalanalyzer
LexicalanalyzerLexicalanalyzer
Lexicalanalyzer
 

More from Ratnakar Mikkili

AI-State Space Representation.pptx
AI-State Space Representation.pptxAI-State Space Representation.pptx
AI-State Space Representation.pptxRatnakar Mikkili
 
AI-State Space Representation.pptx
AI-State Space Representation.pptxAI-State Space Representation.pptx
AI-State Space Representation.pptxRatnakar Mikkili
 
Artificial Intelligence_Searching.pptx
Artificial Intelligence_Searching.pptxArtificial Intelligence_Searching.pptx
Artificial Intelligence_Searching.pptxRatnakar Mikkili
 
Artificial Intelligence_Environment.pptx
Artificial Intelligence_Environment.pptxArtificial Intelligence_Environment.pptx
Artificial Intelligence_Environment.pptxRatnakar Mikkili
 
2_2Specification of Tokens.ppt
2_2Specification of Tokens.ppt2_2Specification of Tokens.ppt
2_2Specification of Tokens.pptRatnakar Mikkili
 
Introduction TO Finite Automata
Introduction TO Finite AutomataIntroduction TO Finite Automata
Introduction TO Finite AutomataRatnakar Mikkili
 

More from Ratnakar Mikkili (9)

AI-State Space Representation.pptx
AI-State Space Representation.pptxAI-State Space Representation.pptx
AI-State Space Representation.pptx
 
AI-State Space Representation.pptx
AI-State Space Representation.pptxAI-State Space Representation.pptx
AI-State Space Representation.pptx
 
Artificial Intelligence_Searching.pptx
Artificial Intelligence_Searching.pptxArtificial Intelligence_Searching.pptx
Artificial Intelligence_Searching.pptx
 
Artificial Intelligence_Environment.pptx
Artificial Intelligence_Environment.pptxArtificial Intelligence_Environment.pptx
Artificial Intelligence_Environment.pptx
 
2_2Specification of Tokens.ppt
2_2Specification of Tokens.ppt2_2Specification of Tokens.ppt
2_2Specification of Tokens.ppt
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Push down automata
Push down automataPush down automata
Push down automata
 
Context free grammar
Context free grammarContext free grammar
Context free grammar
 
Introduction TO Finite Automata
Introduction TO Finite AutomataIntroduction TO Finite Automata
Introduction TO Finite Automata
 

Recently uploaded

Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 

Recently uploaded (20)

Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 

2_4 Finite Automata.ppt

  • 2. 2 Finite Automata • Recognizer for a language – takes an input string & determines whether it’s a valid sentence of the language • Non Deterministic – Has more than one alternative action for the same input symbol • Deterministic – Has at most one action for a given input symbol
  • 3. 3 Finite Automata • Non-Deterministic Finite Automata (NFAs) easily represent regular expression, slower • Deterministic Finite Automata (DFAs) require more complexity to represent regular expressions, faster
  • 4. 4 Non Deterministic Finite Automata • An NFA is a mathematical model that consists of : – S, a set of states – , the symbols of the input alphabet – move, a transition function. • move(state, symbol)  set of states • move : S  {}  S – A state, s0  S, the start state – F  S, a set of final or accepting states.
  • 5. 5 Representation of NFAs • Transition diagrams – 2 edges on same input –  edges are permitted • Transition tables – Suitable for program implementations – Takes up a lot of space when the input alphabet is large – Provides fast access – Adjacency list representation – compact but slow
  • 6. 6 Example (a/b)*abb S = { 0, 1, 2, 3 } s0 = 0 F = { 3 }  = { a, b } start 0 3 b 2 1 b a a b s t a t e i n p u t 0 1 2 a b { 0, 1 } -- { 2 } -- { 3 } { 0 }  (null) moves possible j i  Switch state but do not use any input symbol
  • 7. 7 NFA • An NFA accepts a string x iff there is some path in the transition graph from the start state to some accepting state such that the edge labels along the path spell out x. • Can add dead state to handle all undefined transitions
  • 8. 8 Example (Contd.) start 0 3 b 2 1 b a a b Given an input string, we trace moves If no more input & in final state, ACCEPT EXAMPLE: Input: ababb move(0, a) = 1 move(1, b) = 2 move(2, a) = ? (undefined) REJECT ! move(0, a) = 0 move(0, b) = 0 move(0, a) = 1 move(1, b) = 2 move(2, b) = 3 ACCEPT !
  • 9. 9 Constructing an NFA from a RE • Syntax directed construction procedure • Each step of the construction process introduces at most two new states • Resulting NFA has at most 2 x No. of symbols and operators- states
  • 10. 10 Thompson’s Construction Algorithm • Input: A regular expression r over an alphabet • Output: An NFA N accepting L(r) – First r is parsed into its constituent sub- expressions – Then NFA is constructed for each of the basic symbols – If same symbol occurs repeatedly, separate NFA is constructed for each occurrence
  • 11. 11 Thompson’s Construction Algorithm 2. For a   in the regular expression, construct NFA a start i f L(a) 1. For  in the regular expression, construct NFA L()  start i f
  • 12. 12 Thompson’s Construction Algorithm where i and f are new start / final states, and -moves are introduced from i to the old start states of N(s) and N(t) as well as from all of their final states to f. 3(a) If s, t are regular expressions, N(s), N(t) their NFAs s|t has NFA:  i f  N(s) N(t)   L(s)  L(t)
  • 13. 13 Thompson’s Construction Algorithm 3.(b) If s, t are regular expressions, N(s), N(t) their NFAs st (concatenation) has NFA: start i f N(s) N(t) L(s) L(t) Alternative: overlap N(s)  start i f N(t)   where i is the start state of N(s) (or new under the alternative) and f is the final state of N(t) (or new). Overlap maps final states of N(s) to start state of N(t).
  • 14. 14 Thompson’s Construction Algorithm f N(s)  start i    where : i is new start state and f is new final state -move i to f (to accept null string) -moves i to old start, old final(s) to f -move old final to old start 3.(c) If s is a regular expressions, N(s) its NFA, s* (Kleene star) has NFA:
  • 15. 15 Properties of Construction Let r be a regular expression, with NFA N(r), then • N(r) has #of states  2*(#symbols + #operators) of r • N(r) has exactly one start and one accepting state • Each state of N(r) has at most one outgoing edge a or at most two outgoing ’s • Unique names should be assigned to all states
  • 16. 16 NFA Construction Example r13 r12 r5 r3 r11 r4 r9 r10 r8 r7 r6 r0 r1 r2 b * c a a | ( ) b | * c Example - ab*c | a(b|c*) Parse Tree for this regular expression:
  • 17. 17 NFA Construction Example r3: a r0: b r2: c b     r1: r4 : r1 r2 b     c r5 : r3 r4 b     a c
  • 18. 18 NFA Construction Example r11: a r7: b r6: c c     r9 : r7 | r8   b c     r8: c     r12 : r11 r10   b a r10 : r9
  • 19. 19 NFA Construction Example r13 : r5 | r12 b     a c c       b a     1 6 5 4 3 8 2 10 9 12 13 14 11 15 7 16 17
  • 20. 20 Simulation of an NFA • Given an NFA N constructed by Thompson’s Algorithm and an input string x – determine whether N accepts x • Algorithm reads input one character at a time and computes set of states N could be in after having read each prefix • Runs in time |N| x |x|
  • 21. 21 Simulation of an NFA ε-closure(T) push all states in T onto stack initialize ε-closure(T) to T while stack is not empty pop t from top of stack for each state u with an ε-transition from t if u is not in ε-closure(T) then add u to ε-closure(T) push u onto stack
  • 22. 22 Simulation of an NFA • Input: NFA and input string x • Output: Yes/ No • Similar to Subset construction procedure; Computes ε- closure(move(S,a)) S  -closure({s0}) c  nextchar; while c  eof do S  -closure(move(S,c)); c  nextchar; end; if SF then return “yes” else return “no”
  • 23. 23 Simulation of an NFA • Two Stacks and bit vector implementation of states can be used – Stack 1 – keeps track of current set of states – Stack 2 – To compute next set – Roles of both stacks can be interchanged