SlideShare a Scribd company logo
WELCOME TO A
JOURNEY TO
CS419

Dr. Hussien Sharaf
Computer Science Department

dr.sharaf@from-masr.com
Dr. Hussien M. Sharaf

NON DETERMINISTIC FINITE AUTOMATA NFA


There is a fixed number of states but we can be in multiple states at one
time.

NFA = “a 5-tuple “ (Q, Σ, , q0, F)

Q A finite set of states
Σ
A finite input alphabet
q0 The initial/starting state, q0 is in Q
F
A set of final/accepting states, which is a subset of Q
δ
A transition function, which is a total function from Q x Σ to 2Q ,
this function:

Takes a state and input symbol as arguments.

Returns a set of states instead a single state as in DFA.
δ: (Q x Σ) –> 2Q -2Q is the power set of Q, the set of all subsets of Q
δ(q,s) is a function from Q x S to 2Q (but not to Q)
2
NFA
A finite automaton is deterministic if
 It has no edges/transitions labeled with
epsilon/lamda.
 For each state and for each symbol in the
alphabet, there is exactly one edge labeled
with that symbol.
Dr. Hussien M. Sharaf

NFA


NFA travels all possible paths, and so it remains in many states at once.
As long as at least one of the paths results in an accepting state, the NFA
accepts the input.

Alphabet = {a }
a

q0

q1

a

q2

a

q3
4
Dr. Hussien M. Sharaf

NFA
Alphabet =

{a }

Two choices

a

q0

q1

a

q2

a

q3
5
Dr. Hussien M. Sharaf

NFA
Alphabet =

{a }

Two choices

a

q0

q1

a

q2

No transition

a

q3

No transition

6
Dr. Hussien M. Sharaf

NFA
An NFA accepts a string:
if there is a computation of the NFA
that accepts the string

i.e., all the input string is processed and
the automaton is in an accepting state

7
Dr. Hussien M. Sharaf

Acceptance Example 1

NFA
a

a

a

q0

q1

a

q2

a

q3
8
Dr. Hussien M. Sharaf

First Choice

NFA
a

a

a

q0

q1

a

q2

a

q3
9
Dr. Hussien M. Sharaf

First Choice

NFA
a

a

All input is consumed

a

q0

q1

a

q3

a

q2

“accept”
Dr. Hussien M. Sharaf

Second Choice

NFA
a

a

a

q0

q1

a

q3

a

q2
Dr. Hussien M. Sharaf

Second Choice

NFA
a

a

Input cannot be consumed

a

q1

a

q2

Automaton Halts

q0

a

q 3 “reject”
Dr. Hussien M. Sharaf

NFA

aa is accepted by the NFA:
“accept”

a

q0

q1

q2

a

q0

a

q3

because this
computation
accepts aa

a

q1

a

q2

a

q3

“reject”

this computation
is ignored
13
Dr. Hussien M. Sharaf

NFA
An NFA rejects a string:
if there is no computation of the NFA
that accepts the string.
For each computation:

• All the input is consumed and the
automaton is in a non final state

OR
• The input cannot be consumed
14
Dr. Hussien M. Sharaf

NFA

a

is rejected by the NFA:

“reject”

a

q0

q1

a

q2

a

q0

a

q 3 “reject”

q1

a

q2

a

q3

All possible computations lead to rejection
15
Dr. Hussien M. Sharaf

NFA
aaa is rejected by the NFA:
“reject”

a

q0

q1

a

q2

a

q0

a

q3

q1

a

q2

a

q3

“reject”

All possible computations lead to rejection
16
Dr. Hussien M. Sharaf

LAMBDA TRANSITIONS

q0

a

q1



q2

a

q3

17
Dr. Hussien M. Sharaf

LAMBDA TRANSITIONS

Acceptance Example 2
a

a

q0

a

q1



q2

a

q3

18
Dr. Hussien M. Sharaf

LAMBDA TRANSITIONS

a

a

q0

a

q1



q2

a

q3

19
Dr. Hussien M. Sharaf

LAMBDA TRANSITIONS
input tape head does not move

a

a

q0

a

q1



q2

a

q3
Dr. Hussien M. Sharaf

LAMBDA TRANSITIONS
all input is consumed

a

a

“accept”

q0

a

q1



q2

a

q3

String aa is accepted
21
Dr. Hussien M. Sharaf

LAMBDA TRANSITIONS

Rejection Example 3
a

a

a

q0

a

q1



q2

a

q3

22
Dr. Hussien M. Sharaf

LAMBDA TRANSITIONS

a

a

a

q0

a

q1



q2

a

q3

23
Dr. Hussien M. Sharaf

LAMBDA TRANSITIONS
(read head doesn’t move)

a

a

a

q0

a

q1



q2

a

q3

24
Dr. Hussien M. Sharaf

LAMBDA TRANSITIONS
Input cannot be consumed

a

a

a

Automaton halts

“reject”

q0

a

q1



q2

a

q3

String aaa is rejected
25
Dr. Hussien M. Sharaf

LAMBDA TRANSITIONS

Language accepted:

q0

a

q1



L  {aa }

q2

a

q3

26
Dr. Hussien M. Sharaf

Example 4

q0

a

b

q1

q2



q3


27
Dr. Hussien M. Sharaf

a b

q0

a

b

q1

q2



q3


28
Dr. Hussien M. Sharaf

a b

q0

a

b

q1

q2



q3


29
Dr. Hussien M. Sharaf

a b

“accept”

q0

a

b

q1

q2



q3


30
Dr. Hussien M. Sharaf

Another String

a b a b

q0

a

b

q1

q2



q3


31
Dr. Hussien M. Sharaf

a b a b

q0

a

b

q1

q2



q3


32
Dr. Hussien M. Sharaf

a b a b

q0

a

b

q1

q2



q3


33
Dr. Hussien M. Sharaf

a b a b

q0

a

b

q1

q2



q3


34
Dr. Hussien M. Sharaf

a b a b

q0

a

b

q1

q2



q3


35
Dr. Hussien M. Sharaf

a b a b

q0

a

b

q1

q2



q3


36
Dr. Hussien M. Sharaf

a b a b

“accept”

q0

a

b

q1

q2



q3


37
Dr. Hussien M. Sharaf

Language accepted

L  ab , abab , ababab , ... 
 ab 

q0

a



b

q1

q2



q3


38
Dr. Hussien M. Sharaf

EXAMPLE 5

0
q0

1

q1

0, 1

q2


39
Dr. Hussien M. Sharaf

Language accepted

L ( M ) = {λ , 10 , 1010 , 101010 , ... }
= {10 } *

0
q0

1

q1

0, 1

q2

(redundant
state)


40
DETERMINISTIC AND
NONDETERMINISTIC AUTOMATA


Deterministic Finite Automata (DFA)
 One

transition per input per state
 No -moves


Nondeterministic Finite Automata (NFA)
 Can

have multiple transitions for one input in a
given state
 Can have -moves

41
THANK YOU

Dr. Hussien M. Sharaf

42

More Related Content

What's hot

String Matching Finite Automata & KMP Algorithm.
String Matching Finite Automata & KMP Algorithm.String Matching Finite Automata & KMP Algorithm.
String Matching Finite Automata & KMP Algorithm.
Malek Sumaiya
 
Formal Logic - Lesson 7 - Rules of Inference
Formal Logic - Lesson 7 - Rules of InferenceFormal Logic - Lesson 7 - Rules of Inference
Formal Logic - Lesson 7 - Rules of Inference
Laguna State Polytechnic University
 
Theory of Computation Regular Expressions, Minimisation & Pumping Lemma
Theory of Computation Regular Expressions, Minimisation & Pumping LemmaTheory of Computation Regular Expressions, Minimisation & Pumping Lemma
Theory of Computation Regular Expressions, Minimisation & Pumping Lemma
Rushabh2428
 
γ Regular-open sets and γ-extremally disconnected spaces
γ Regular-open sets and γ-extremally disconnected spacesγ Regular-open sets and γ-extremally disconnected spaces
γ Regular-open sets and γ-extremally disconnected spaces
Alexander Decker
 
Formal Logic - Lesson 4 - Tautology, Contradiction and Contingency
Formal Logic - Lesson 4 - Tautology, Contradiction and ContingencyFormal Logic - Lesson 4 - Tautology, Contradiction and Contingency
Formal Logic - Lesson 4 - Tautology, Contradiction and Contingency
Laguna State Polytechnic University
 
applications of first order non linear partial differential equation
applications of first order non linear partial differential equationapplications of first order non linear partial differential equation
applications of first order non linear partial differential equation
Dhananjaysinh Jhala
 
Truth table
Truth tableTruth table
Truth table
Abdur Rehman
 
25 String Matching
25 String Matching25 String Matching
25 String Matching
Andres Mendez-Vazquez
 
Mba admission in india
Mba admission in indiaMba admission in india
Mba admission in india
Edhole.com
 
Mathematical Logic
Mathematical LogicMathematical Logic
Mathematical Logic
endahnurfebriyanti
 
Truth, deduction, computation; lecture 5
Truth, deduction, computation;  lecture 5Truth, deduction, computation;  lecture 5
Truth, deduction, computation; lecture 5
Vlad Patryshev
 
Proofs by contraposition
Proofs by contrapositionProofs by contraposition
Proofs by contraposition
Abdur Rehman
 
Formal Logic - Lesson 8 - Predicates and Quantifiers
Formal Logic - Lesson 8 - Predicates and QuantifiersFormal Logic - Lesson 8 - Predicates and Quantifiers
Formal Logic - Lesson 8 - Predicates and Quantifiers
Laguna State Polytechnic University
 
Computer Organization and Assembly Language
Computer Organization and Assembly LanguageComputer Organization and Assembly Language
Computer Organization and Assembly Language
Raquel Mulles
 
Formal Logic - Lesson 6 - Switching Circuits
Formal Logic - Lesson 6 - Switching CircuitsFormal Logic - Lesson 6 - Switching Circuits
Formal Logic - Lesson 6 - Switching Circuits
Laguna State Polytechnic University
 
Math 189 Exam 1 Solutions
Math 189 Exam 1 SolutionsMath 189 Exam 1 Solutions
Math 189 Exam 1 Solutions
Tyler Murphy
 
Method of direct proof
Method of direct proofMethod of direct proof
Method of direct proof
Abdur Rehman
 
Fourier Series - Engineering Mathematics
Fourier Series -  Engineering MathematicsFourier Series -  Engineering Mathematics
Fourier Series - Engineering Mathematics
Md Sadequl Islam
 
Formal Logic - Lesson 5 - Logical Equivalence
Formal Logic - Lesson 5 - Logical EquivalenceFormal Logic - Lesson 5 - Logical Equivalence
Formal Logic - Lesson 5 - Logical Equivalence
Laguna State Polytechnic University
 

What's hot (20)

String Matching Finite Automata & KMP Algorithm.
String Matching Finite Automata & KMP Algorithm.String Matching Finite Automata & KMP Algorithm.
String Matching Finite Automata & KMP Algorithm.
 
Formal Logic - Lesson 7 - Rules of Inference
Formal Logic - Lesson 7 - Rules of InferenceFormal Logic - Lesson 7 - Rules of Inference
Formal Logic - Lesson 7 - Rules of Inference
 
Theory of Computation Regular Expressions, Minimisation & Pumping Lemma
Theory of Computation Regular Expressions, Minimisation & Pumping LemmaTheory of Computation Regular Expressions, Minimisation & Pumping Lemma
Theory of Computation Regular Expressions, Minimisation & Pumping Lemma
 
γ Regular-open sets and γ-extremally disconnected spaces
γ Regular-open sets and γ-extremally disconnected spacesγ Regular-open sets and γ-extremally disconnected spaces
γ Regular-open sets and γ-extremally disconnected spaces
 
Formal Logic - Lesson 4 - Tautology, Contradiction and Contingency
Formal Logic - Lesson 4 - Tautology, Contradiction and ContingencyFormal Logic - Lesson 4 - Tautology, Contradiction and Contingency
Formal Logic - Lesson 4 - Tautology, Contradiction and Contingency
 
applications of first order non linear partial differential equation
applications of first order non linear partial differential equationapplications of first order non linear partial differential equation
applications of first order non linear partial differential equation
 
Truth table
Truth tableTruth table
Truth table
 
25 String Matching
25 String Matching25 String Matching
25 String Matching
 
Mba admission in india
Mba admission in indiaMba admission in india
Mba admission in india
 
Mathematical Logic
Mathematical LogicMathematical Logic
Mathematical Logic
 
Truth, deduction, computation; lecture 5
Truth, deduction, computation;  lecture 5Truth, deduction, computation;  lecture 5
Truth, deduction, computation; lecture 5
 
Proofs by contraposition
Proofs by contrapositionProofs by contraposition
Proofs by contraposition
 
Indices & logarithm
Indices & logarithmIndices & logarithm
Indices & logarithm
 
Formal Logic - Lesson 8 - Predicates and Quantifiers
Formal Logic - Lesson 8 - Predicates and QuantifiersFormal Logic - Lesson 8 - Predicates and Quantifiers
Formal Logic - Lesson 8 - Predicates and Quantifiers
 
Computer Organization and Assembly Language
Computer Organization and Assembly LanguageComputer Organization and Assembly Language
Computer Organization and Assembly Language
 
Formal Logic - Lesson 6 - Switching Circuits
Formal Logic - Lesson 6 - Switching CircuitsFormal Logic - Lesson 6 - Switching Circuits
Formal Logic - Lesson 6 - Switching Circuits
 
Math 189 Exam 1 Solutions
Math 189 Exam 1 SolutionsMath 189 Exam 1 Solutions
Math 189 Exam 1 Solutions
 
Method of direct proof
Method of direct proofMethod of direct proof
Method of direct proof
 
Fourier Series - Engineering Mathematics
Fourier Series -  Engineering MathematicsFourier Series -  Engineering Mathematics
Fourier Series - Engineering Mathematics
 
Formal Logic - Lesson 5 - Logical Equivalence
Formal Logic - Lesson 5 - Logical EquivalenceFormal Logic - Lesson 5 - Logical Equivalence
Formal Logic - Lesson 5 - Logical Equivalence
 

More from Arab Open University and Cairo University

Infos2014
Infos2014Infos2014
File Organization & processing Mid term summer 2014 - modelanswer
File Organization & processing Mid term summer 2014 - modelanswerFile Organization & processing Mid term summer 2014 - modelanswer
File Organization & processing Mid term summer 2014 - modelanswer
Arab Open University and Cairo University
 
Model answer of compilers june spring 2013
Model answer of compilers june spring 2013Model answer of compilers june spring 2013
Model answer of compilers june spring 2013
Arab Open University and Cairo University
 
Model answer of exam TC_spring 2013
Model answer of exam TC_spring 2013Model answer of exam TC_spring 2013
Model answer of exam TC_spring 2013
Arab Open University and Cairo University
 
Theory of computation Lec3 dfa
Theory of computation Lec3 dfaTheory of computation Lec3 dfa
Theory of computation Lec3 dfa
Arab Open University and Cairo University
 
Theory of computation Lec2
Theory of computation Lec2Theory of computation Lec2
Theory of computation Lec2
Arab Open University and Cairo University
 
Theory of computation Lec7 pda
Theory of computation Lec7 pdaTheory of computation Lec7 pda
Theory of computation Lec7 pda
Arab Open University and Cairo University
 
Setup python with eclipse
Setup python with eclipseSetup python with eclipse
Compilers Final spring 2013 model answer
 Compilers Final spring 2013 model answer Compilers Final spring 2013 model answer
Compilers Final spring 2013 model answer
Arab Open University and Cairo University
 

More from Arab Open University and Cairo University (20)

Infos2014
Infos2014Infos2014
Infos2014
 
File Organization & processing Mid term summer 2014 - modelanswer
File Organization & processing Mid term summer 2014 - modelanswerFile Organization & processing Mid term summer 2014 - modelanswer
File Organization & processing Mid term summer 2014 - modelanswer
 
Model answer of compilers june spring 2013
Model answer of compilers june spring 2013Model answer of compilers june spring 2013
Model answer of compilers june spring 2013
 
Model answer of exam TC_spring 2013
Model answer of exam TC_spring 2013Model answer of exam TC_spring 2013
Model answer of exam TC_spring 2013
 
Theory of computation Lec6
Theory of computation Lec6Theory of computation Lec6
Theory of computation Lec6
 
Theory of computation Lec3 dfa
Theory of computation Lec3 dfaTheory of computation Lec3 dfa
Theory of computation Lec3 dfa
 
Theory of computation Lec2
Theory of computation Lec2Theory of computation Lec2
Theory of computation Lec2
 
Theory of computation Lec1
Theory of computation Lec1Theory of computation Lec1
Theory of computation Lec1
 
Theory of computation Lec7 pda
Theory of computation Lec7 pdaTheory of computation Lec7 pda
Theory of computation Lec7 pda
 
Setup python with eclipse
Setup python with eclipseSetup python with eclipse
Setup python with eclipse
 
Cs419 lec8 top-down parsing
Cs419 lec8    top-down parsingCs419 lec8    top-down parsing
Cs419 lec8 top-down parsing
 
Cs419 lec11 bottom-up parsing
Cs419 lec11   bottom-up parsingCs419 lec11   bottom-up parsing
Cs419 lec11 bottom-up parsing
 
Cs419 lec12 semantic analyzer
Cs419 lec12  semantic analyzerCs419 lec12  semantic analyzer
Cs419 lec12 semantic analyzer
 
Cs419 lec9 constructing parsing table ll1
Cs419 lec9   constructing parsing table ll1Cs419 lec9   constructing parsing table ll1
Cs419 lec9 constructing parsing table ll1
 
Cs419 lec10 left recursion and left factoring
Cs419 lec10   left recursion and left factoringCs419 lec10   left recursion and left factoring
Cs419 lec10 left recursion and left factoring
 
Cs419 lec7 cfg
Cs419 lec7   cfgCs419 lec7   cfg
Cs419 lec7 cfg
 
Cs419 lec3 lexical analysis using re
Cs419 lec3   lexical analysis using reCs419 lec3   lexical analysis using re
Cs419 lec3 lexical analysis using re
 
Compilers Final spring 2013 model answer
 Compilers Final spring 2013 model answer Compilers Final spring 2013 model answer
Compilers Final spring 2013 model answer
 
Compilers midterm spring 2013 model answer
Compilers midterm spring 2013   model answerCompilers midterm spring 2013   model answer
Compilers midterm spring 2013 model answer
 
Cs419 Compiler lec1&2 introduction
Cs419 Compiler lec1&2  introductionCs419 Compiler lec1&2  introduction
Cs419 Compiler lec1&2 introduction
 

Recently uploaded

TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 

Recently uploaded (20)

TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 

Cs419 lec6 lexical analysis using nfa

  • 1. WELCOME TO A JOURNEY TO CS419 Dr. Hussien Sharaf Computer Science Department dr.sharaf@from-masr.com
  • 2. Dr. Hussien M. Sharaf NON DETERMINISTIC FINITE AUTOMATA NFA  There is a fixed number of states but we can be in multiple states at one time. NFA = “a 5-tuple “ (Q, Σ, , q0, F) Q A finite set of states Σ A finite input alphabet q0 The initial/starting state, q0 is in Q F A set of final/accepting states, which is a subset of Q δ A transition function, which is a total function from Q x Σ to 2Q , this function:  Takes a state and input symbol as arguments.  Returns a set of states instead a single state as in DFA. δ: (Q x Σ) –> 2Q -2Q is the power set of Q, the set of all subsets of Q δ(q,s) is a function from Q x S to 2Q (but not to Q) 2
  • 3. NFA A finite automaton is deterministic if  It has no edges/transitions labeled with epsilon/lamda.  For each state and for each symbol in the alphabet, there is exactly one edge labeled with that symbol.
  • 4. Dr. Hussien M. Sharaf NFA  NFA travels all possible paths, and so it remains in many states at once. As long as at least one of the paths results in an accepting state, the NFA accepts the input. Alphabet = {a } a q0 q1 a q2 a q3 4
  • 5. Dr. Hussien M. Sharaf NFA Alphabet = {a } Two choices a q0 q1 a q2 a q3 5
  • 6. Dr. Hussien M. Sharaf NFA Alphabet = {a } Two choices a q0 q1 a q2 No transition a q3 No transition 6
  • 7. Dr. Hussien M. Sharaf NFA An NFA accepts a string: if there is a computation of the NFA that accepts the string i.e., all the input string is processed and the automaton is in an accepting state 7
  • 8. Dr. Hussien M. Sharaf Acceptance Example 1 NFA a a a q0 q1 a q2 a q3 8
  • 9. Dr. Hussien M. Sharaf First Choice NFA a a a q0 q1 a q2 a q3 9
  • 10. Dr. Hussien M. Sharaf First Choice NFA a a All input is consumed a q0 q1 a q3 a q2 “accept”
  • 11. Dr. Hussien M. Sharaf Second Choice NFA a a a q0 q1 a q3 a q2
  • 12. Dr. Hussien M. Sharaf Second Choice NFA a a Input cannot be consumed a q1 a q2 Automaton Halts q0 a q 3 “reject”
  • 13. Dr. Hussien M. Sharaf NFA aa is accepted by the NFA: “accept” a q0 q1 q2 a q0 a q3 because this computation accepts aa a q1 a q2 a q3 “reject” this computation is ignored 13
  • 14. Dr. Hussien M. Sharaf NFA An NFA rejects a string: if there is no computation of the NFA that accepts the string. For each computation: • All the input is consumed and the automaton is in a non final state OR • The input cannot be consumed 14
  • 15. Dr. Hussien M. Sharaf NFA a is rejected by the NFA: “reject” a q0 q1 a q2 a q0 a q 3 “reject” q1 a q2 a q3 All possible computations lead to rejection 15
  • 16. Dr. Hussien M. Sharaf NFA aaa is rejected by the NFA: “reject” a q0 q1 a q2 a q0 a q3 q1 a q2 a q3 “reject” All possible computations lead to rejection 16
  • 17. Dr. Hussien M. Sharaf LAMBDA TRANSITIONS q0 a q1  q2 a q3 17
  • 18. Dr. Hussien M. Sharaf LAMBDA TRANSITIONS Acceptance Example 2 a a q0 a q1  q2 a q3 18
  • 19. Dr. Hussien M. Sharaf LAMBDA TRANSITIONS a a q0 a q1  q2 a q3 19
  • 20. Dr. Hussien M. Sharaf LAMBDA TRANSITIONS input tape head does not move a a q0 a q1  q2 a q3
  • 21. Dr. Hussien M. Sharaf LAMBDA TRANSITIONS all input is consumed a a “accept” q0 a q1  q2 a q3 String aa is accepted 21
  • 22. Dr. Hussien M. Sharaf LAMBDA TRANSITIONS Rejection Example 3 a a a q0 a q1  q2 a q3 22
  • 23. Dr. Hussien M. Sharaf LAMBDA TRANSITIONS a a a q0 a q1  q2 a q3 23
  • 24. Dr. Hussien M. Sharaf LAMBDA TRANSITIONS (read head doesn’t move) a a a q0 a q1  q2 a q3 24
  • 25. Dr. Hussien M. Sharaf LAMBDA TRANSITIONS Input cannot be consumed a a a Automaton halts “reject” q0 a q1  q2 a q3 String aaa is rejected 25
  • 26. Dr. Hussien M. Sharaf LAMBDA TRANSITIONS Language accepted: q0 a q1  L  {aa } q2 a q3 26
  • 27. Dr. Hussien M. Sharaf Example 4 q0 a b q1 q2  q3  27
  • 28. Dr. Hussien M. Sharaf a b q0 a b q1 q2  q3  28
  • 29. Dr. Hussien M. Sharaf a b q0 a b q1 q2  q3  29
  • 30. Dr. Hussien M. Sharaf a b “accept” q0 a b q1 q2  q3  30
  • 31. Dr. Hussien M. Sharaf Another String a b a b q0 a b q1 q2  q3  31
  • 32. Dr. Hussien M. Sharaf a b a b q0 a b q1 q2  q3  32
  • 33. Dr. Hussien M. Sharaf a b a b q0 a b q1 q2  q3  33
  • 34. Dr. Hussien M. Sharaf a b a b q0 a b q1 q2  q3  34
  • 35. Dr. Hussien M. Sharaf a b a b q0 a b q1 q2  q3  35
  • 36. Dr. Hussien M. Sharaf a b a b q0 a b q1 q2  q3  36
  • 37. Dr. Hussien M. Sharaf a b a b “accept” q0 a b q1 q2  q3  37
  • 38. Dr. Hussien M. Sharaf Language accepted L  ab , abab , ababab , ...   ab  q0 a  b q1 q2  q3  38
  • 39. Dr. Hussien M. Sharaf EXAMPLE 5 0 q0 1 q1 0, 1 q2  39
  • 40. Dr. Hussien M. Sharaf Language accepted L ( M ) = {λ , 10 , 1010 , 101010 , ... } = {10 } * 0 q0 1 q1 0, 1 q2 (redundant state)  40
  • 41. DETERMINISTIC AND NONDETERMINISTIC AUTOMATA  Deterministic Finite Automata (DFA)  One transition per input per state  No -moves  Nondeterministic Finite Automata (NFA)  Can have multiple transitions for one input in a given state  Can have -moves 41
  • 42. THANK YOU Dr. Hussien M. Sharaf 42