SlideShare ist ein Scribd-Unternehmen logo
1 von 42
Dr. Hussien Sharaf
Computer Science Department
dr.sharaf@from-masr.com
CS 611
Finite Automata FA
 It started as a simple automatic device with no memory.
We still need it to study how to model a device and
model its capability.
 Its goal is to act as a recognizer for specific a
language/pattern.
 Any problem can be presented in form of a decidable
problem that can be answered by Yes/No.
 A problem can be concatenated to one of its possible
solutions and can be seen as a string that matches a
pattern.
 Hence FA (machine with limited memory) can solve any
problem.
Dr. Hussien M. Sharaf 2
 FA = “a 5-tuple “ (Q, Σ, , q0, F)
1. Q: {q0, q1, q2, …} is set of states.
2. Σ: {a, b, …} set of alphabet.
3. (delta): represents the set of transitions that
FA can take between its states.
: Q x Σ→Q
Q x Σ to Q, this function:
 Takes a state and input symbol as arguments.
 Returns a single state.
4. q0 Q is the start state.
5. F Q is the set of final/accepting states.
Dr. Hussien M. Sharaf
Deterministic Finite Automata DFA


3
 : Q x Σ→Q
Maps from domain of (state, letter) to range of states.
Transition function
(q0, a)
(q2, b)
(q1, b)
q1
q2
q3
Dr. Hussien M. Sharaf 4
(q0, b)
Lets name it Conditional consumption instead of
transition
λ: Q x Q → Σ
Maps from domain of (states, states) to range of letters.
Renaming function to λ (Lamda)
Σ(q0, q1)
(q2, q3)
(q1, q3)
a
Dr. Hussien M. Sharaf 5
b
c
Allows more than one link
from domain to codomain
Not recommended
How does FA work?
1. Starts from a start state.
2. Loop
Reads a letters from the input
3. Until input string finishes
4. If the current state is a final state then
Input string is accepted.
5. Else
Input string is NOT accepted.
 But how can FA be designed and represented?
Dr. Hussien M. Sharaf 6
Representation of FA: Graph
 States= nodes
 Starting state denoted by –
 Final state(s) denoted by +
 Transition function =directed arrows connecting
states.
 Build an FA for RE “a*b(a+b)*”
Dr. Hussien M. Sharaf
S1
- +
S2
b
a a,b
7
Representation of FA: Table
Dr. Hussien M. Sharaf
a b
-s1 s1 s2
+s2 s2 s2
Rows = states
input symbols
Final states
Indicated
by “+”
“-” sign for
start state
8
Example1.1
 Build an FA that accepts only aab
Dr. Hussien M. Sharaf
S1
-
S3
a
S2
a b
+
S4
S5
b
b
a
a,b
a b
S1 S2 S5
S2 S3 S5
S3 S5 S4
S4 S5 S5
9
a,b
Example1.2
 Build an FA that accepts only aab
Dr. Hussien M. Sharaf
S1
-
S3
a
S2
a b
+
S4
a b
S1 S2 ?
S2 S3 ?
S3 ? ?
S4 ? ?
10
Ex2
 (a+b)*
Dr. Hussien M. Sharaf
a, b
±
11
FA accepting nothing
1. FA with no final states
Dr. Hussien M. Sharaf
a
-
a,b
b
2. FA with disconnected graph. Start state does not
have a path to the final state.
a
-
a,b
b
+
b
12
Ex3
 All words with even count of letters.
((a+b)(a+b))*
Dr. Hussien M. Sharaf 13
1± 2
a, b
a, b
Ex4.1
 All words that start with “a”
a(a+b)*
Dr. Hussien M. Sharaf 14
1-
2
b
a 3 + a,b
1-
2b
a 3 +
a,b
a,b
Does not accept all inputs
Ex4.2
 All words that start with “a”
a(a+b)*
Dr. Hussien M. Sharaf 15
1-
2b
a
3 +
a,b
a,b
Special accept state for string “a”, might give
better performance in hardware
implementation
Ex5
 All words that start with triple letter
(aaa+bbb)(a+b)*
Dr. Hussien M. Sharaf 16
1-
2a 3
a,b
4
b 5
b
6+
b
a a
Ex6
 {aa, ba, baba, aaaa, bbba, abba, aaabaa, …}
 All words with even count of letters and ends
with “a”. (a+b)a ((a+b)a (b(a+b)a)* )*
Dr. Hussien M. Sharaf 17
-
a,b
+
a,b
5
b
a
a,b
Ex7
 {aa, ba, baba, aaaa, ab, bb, bababa, aaba, …}
 All words with even count of letters having “a”
in an even position from the start, where the first
letter is letter number one. (a+b)a((a+b)a)*
Dr. Hussien M. Sharaf 18
-
a,b
Ex8 Cohen 2nd
edition page 63
 Consider the following FA:
Dr. Hussien M. Sharaf 19
•Whenever aa exists, the first
“a” must take us to state 4 or
state 2.
•Either way, the next a takes us
to state 4. Similar situation with
“bb”.
In summary: this FA accepts strings that have a
double letter in them.
(a + b)*(aa + bb)(a + b)*
Ex9 Cohen 2nd
edition page 64
 Consider the following FA:
Dr. Hussien M. Sharaf 20
•Accepts all words with b as the
third letter and reject all other
words.
•A word that has fewer than
three letters fails.
RE1: (aab + abb + bab + bbb)(a + b)*
OR :(a + b)(a + b)(b)(a + b)* = (a + b)2
b (a + b)*
Notice that this last formula is not strictly speaking
a regular expression, since it uses the symbol “2”
Have you see any memory?
Ex10
 All strings that end in ab.
 Do we need a memory to remember the last two letters?
Dr. Hussien M. Sharaf 21
-
a
b
…
…
……
+
a
b
a
b
a
b
b
b
b
b
a
Ex11
 Even-Even :
 All the words that end in state
3 have an even number of b's
but an odd number of a's.
 All words that end in state 4
have an odd number of a's
and an odd number of b's.
 Any EVEN-EVEN words
must end in state 1 and be
accepted.
Dr. Hussien M. Sharaf 22
Dr. Hussien M. Sharaf 23
Automaton
CPU
input memory
output memory
Program memory
temporary memory
Automaton
Dr. Hussien M. Sharaf 24
Finite Automaton
Input
String
Output
String
Finite
Automaton
Dr. Hussien M. Sharaf 25
Different Kinds of Automata
Automata are distinguished by the temporary
memory:
• Finite Automata: no temporary memory
• Pushdown Automata: stack
• Turing Machines: random access memory
Dr. Hussien M. Sharaf 26
Finite
Automata
Pushdown
Automata
Turing
Machine
Power of Automata
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 union {Λ}
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)
Dr. Hussien M. Sharaf 27
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.
29
1q 2q
3q
a
a
a
0q
}{aAlphabet =
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.
Dr. Hussien M. Sharaf
30
1q 2q
3q
a
a
a
0q
Two choices
}{aAlphabet =
NFA
Dr. Hussien M. Sharaf
31
No transition
1q 2q
3q
a
a
a
0q
Two choices
No transition
}{aAlphabet =
NFA
Dr. Hussien M. Sharaf
32
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
NFA
Dr. Hussien M. Sharaf
33
a a
0q
1q 2q
3q
a
a
Acceptance Example 1
a
NFA
Dr. Hussien M. Sharaf
34
a a
0q
1q 2q
a
a
a
NFA
Dr. Hussien M. Sharaf
3q
35
a a
0q
a
a
a
NFA
Dr. Hussien M. Sharaf
3q “reject”
2q “accept”
1q
36
aa is accepted by the NFA:
0q
1q 2q
3q
a
a
a
“accept”
0q
1q 2q
a
a
a
3q “reject”
because this
computation
accepts aa
this computation
is ignored
NFA
Dr. Hussien M. Sharaf
Dr. Hussien M. Sharaf 37
An NFA rejects a string:
if there is no computation of the NFA
that accepts the string.
• All the input is consumed and the
automaton is in a non final state
• The input cannot be consumed (indecidable input)
OR
For each computation:
NFA
38
a is rejected by the NFA:
0q
1q 2q
a
a
a
3q “reject”
0q
1q 2q
a
a
a
3q
“reject”
All possible computations lead to rejection
NFA
Dr. Hussien M. Sharaf
39
aaa is rejected by the NFA:
0q
1q 2q
3q
a
a
a
“reject”
0q
1q 2q
a
a
a
3q “reject”
All possible computations lead to rejection
NFA
Dr. Hussien M. Sharaf
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
Assignment 4
 Proof that NFA and DFA are equivalent.
Constructive type of proofs might be the most
appropriate.
Be formal and simple. Don’t exceed 2-3 slides.
You might study the proof from “Sipser” book
or “Models Of Computation”.
Your answer might be delivered in form of
slides to Eng. Eman“e.hossny@fci-cu.edu.eg”
and CC to my email dr.sharaf@from-masr.com.
You will present your slides in 5-7 minutes.
Dr. Hussien M. Sharaf 41
Thank you
Dr. Hussien M. Sharaf 42

Weitere ähnliche Inhalte

Was ist angesagt?

Regular Expression to Finite Automata
Regular Expression to Finite AutomataRegular Expression to Finite Automata
Regular Expression to Finite AutomataArchana Gopinath
 
Deterministic Finite Automata (DFA)
Deterministic Finite Automata (DFA)Deterministic Finite Automata (DFA)
Deterministic Finite Automata (DFA)Animesh Chaturvedi
 
Intro automata theory
Intro automata theory Intro automata theory
Intro automata theory Rajendran
 
Finite Automata in compiler design
Finite Automata in compiler designFinite Automata in compiler design
Finite Automata in compiler designRiazul Islam
 
TOC 1 | Introduction to Theory of Computation
TOC 1 | Introduction to Theory of ComputationTOC 1 | Introduction to Theory of Computation
TOC 1 | Introduction to Theory of ComputationMohammad Imam Hossain
 
Chapter1 Formal Language and Automata Theory
Chapter1 Formal Language and Automata TheoryChapter1 Formal Language and Automata Theory
Chapter1 Formal Language and Automata TheoryTsegazeab Asgedom
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionsShiraz316
 
Theory of computing
Theory of computingTheory of computing
Theory of computingRanjan Kumar
 
Finite automata(For college Seminars)
Finite automata(For college Seminars)Finite automata(For college Seminars)
Finite automata(For college Seminars)Naman Joshi
 
TOC 4 | Non-deterministic Finite Automata
TOC 4 | Non-deterministic Finite AutomataTOC 4 | Non-deterministic Finite Automata
TOC 4 | Non-deterministic Finite AutomataMohammad Imam Hossain
 
Types of grammer - TOC
Types of grammer - TOCTypes of grammer - TOC
Types of grammer - TOCAbhayDhupar
 
Push down automata
Push down automataPush down automata
Push down automataSomya Bagai
 
Nondeterministic Finite Automata
Nondeterministic Finite AutomataNondeterministic Finite Automata
Nondeterministic Finite AutomataAdel Al-Ofairi
 
Pumping lemma Theory Of Automata
Pumping lemma Theory Of AutomataPumping lemma Theory Of Automata
Pumping lemma Theory Of Automatahafizhamza0322
 
closure properties of regular language.pptx
closure properties of regular language.pptxclosure properties of regular language.pptx
closure properties of regular language.pptxThirumoorthy64
 

Was ist angesagt? (20)

Flat unit 1
Flat unit 1Flat unit 1
Flat unit 1
 
Regular Expression to Finite Automata
Regular Expression to Finite AutomataRegular Expression to Finite Automata
Regular Expression to Finite Automata
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Deterministic Finite Automata (DFA)
Deterministic Finite Automata (DFA)Deterministic Finite Automata (DFA)
Deterministic Finite Automata (DFA)
 
Intro automata theory
Intro automata theory Intro automata theory
Intro automata theory
 
TOC 5 | Regular Expressions
TOC 5 | Regular ExpressionsTOC 5 | Regular Expressions
TOC 5 | Regular Expressions
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
 
Finite Automata in compiler design
Finite Automata in compiler designFinite Automata in compiler design
Finite Automata in compiler design
 
TOC 1 | Introduction to Theory of Computation
TOC 1 | Introduction to Theory of ComputationTOC 1 | Introduction to Theory of Computation
TOC 1 | Introduction to Theory of Computation
 
Chapter1 Formal Language and Automata Theory
Chapter1 Formal Language and Automata TheoryChapter1 Formal Language and Automata Theory
Chapter1 Formal Language and Automata Theory
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Turing machine by_deep
Turing machine by_deepTuring machine by_deep
Turing machine by_deep
 
Theory of computing
Theory of computingTheory of computing
Theory of computing
 
Finite automata(For college Seminars)
Finite automata(For college Seminars)Finite automata(For college Seminars)
Finite automata(For college Seminars)
 
TOC 4 | Non-deterministic Finite Automata
TOC 4 | Non-deterministic Finite AutomataTOC 4 | Non-deterministic Finite Automata
TOC 4 | Non-deterministic Finite Automata
 
Types of grammer - TOC
Types of grammer - TOCTypes of grammer - TOC
Types of grammer - TOC
 
Push down automata
Push down automataPush down automata
Push down automata
 
Nondeterministic Finite Automata
Nondeterministic Finite AutomataNondeterministic Finite Automata
Nondeterministic Finite Automata
 
Pumping lemma Theory Of Automata
Pumping lemma Theory Of AutomataPumping lemma Theory Of Automata
Pumping lemma Theory Of Automata
 
closure properties of regular language.pptx
closure properties of regular language.pptxclosure properties of regular language.pptx
closure properties of regular language.pptx
 

Ähnlich wie Theory of computation Lec3 dfa

Ähnlich wie Theory of computation Lec3 dfa (20)

Cs419 lec5 lexical analysis using dfa
Cs419 lec5   lexical analysis using dfaCs419 lec5   lexical analysis using dfa
Cs419 lec5 lexical analysis using dfa
 
Cs419 lec6 lexical analysis using nfa
Cs419 lec6   lexical analysis using nfaCs419 lec6   lexical analysis using nfa
Cs419 lec6 lexical analysis using nfa
 
flat unit1
flat unit1flat unit1
flat unit1
 
Automata theory introduction
Automata theory introductionAutomata theory introduction
Automata theory introduction
 
Automata Theory
Automata TheoryAutomata Theory
Automata Theory
 
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
 
Lec4
Lec4Lec4
Lec4
 
Cs419 lec7 cfg
Cs419 lec7   cfgCs419 lec7   cfg
Cs419 lec7 cfg
 
CS 5th.pptx
CS 5th.pptxCS 5th.pptx
CS 5th.pptx
 
ω Automaton
ω Automatonω Automaton
ω Automaton
 
Programmable PN Sequence Generators
Programmable PN Sequence GeneratorsProgrammable PN Sequence Generators
Programmable PN Sequence Generators
 
Final fa part1
Final fa part1Final fa part1
Final fa part1
 
RegularLanguageProperties [Autosaved].pptx
RegularLanguageProperties [Autosaved].pptxRegularLanguageProperties [Autosaved].pptx
RegularLanguageProperties [Autosaved].pptx
 
Finite State Machines with Output
Finite State Machines with OutputFinite State Machines with Output
Finite State Machines with Output
 
K11038 Mayur control ppt
K11038 Mayur control pptK11038 Mayur control ppt
K11038 Mayur control ppt
 
5. NFA & DFA.pdf
5. NFA & DFA.pdf5. NFA & DFA.pdf
5. NFA & DFA.pdf
 
Nondeterministic Finite Automat
Nondeterministic Finite AutomatNondeterministic Finite Automat
Nondeterministic Finite Automat
 
Csr2011 june17 14_00_bulatov
Csr2011 june17 14_00_bulatovCsr2011 june17 14_00_bulatov
Csr2011 june17 14_00_bulatov
 
Cs419 lec3 lexical analysis using re
Cs419 lec3   lexical analysis using reCs419 lec3   lexical analysis using re
Cs419 lec3 lexical analysis using re
 

Mehr von Arab Open University and Cairo University

Mehr von 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 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 lec4 lexical analysis using re
Cs419 lec4   lexical analysis using reCs419 lec4   lexical analysis using re
Cs419 lec4 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
 
Final Exam OS fall 2012-2013 with answers
Final Exam OS fall 2012-2013 with answersFinal Exam OS fall 2012-2013 with answers
Final Exam OS fall 2012-2013 with answers
 
CS215 - Lec 8 searching records
CS215 - Lec 8  searching recordsCS215 - Lec 8  searching records
CS215 - Lec 8 searching records
 

Kürzlich hochgeladen

Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 

Kürzlich hochgeladen (20)

Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 

Theory of computation Lec3 dfa

  • 1. Dr. Hussien Sharaf Computer Science Department dr.sharaf@from-masr.com CS 611
  • 2. Finite Automata FA  It started as a simple automatic device with no memory. We still need it to study how to model a device and model its capability.  Its goal is to act as a recognizer for specific a language/pattern.  Any problem can be presented in form of a decidable problem that can be answered by Yes/No.  A problem can be concatenated to one of its possible solutions and can be seen as a string that matches a pattern.  Hence FA (machine with limited memory) can solve any problem. Dr. Hussien M. Sharaf 2
  • 3.  FA = “a 5-tuple “ (Q, Σ, , q0, F) 1. Q: {q0, q1, q2, …} is set of states. 2. Σ: {a, b, …} set of alphabet. 3. (delta): represents the set of transitions that FA can take between its states. : Q x Σ→Q Q x Σ to Q, this function:  Takes a state and input symbol as arguments.  Returns a single state. 4. q0 Q is the start state. 5. F Q is the set of final/accepting states. Dr. Hussien M. Sharaf Deterministic Finite Automata DFA   3
  • 4.  : Q x Σ→Q Maps from domain of (state, letter) to range of states. Transition function (q0, a) (q2, b) (q1, b) q1 q2 q3 Dr. Hussien M. Sharaf 4 (q0, b)
  • 5. Lets name it Conditional consumption instead of transition λ: Q x Q → Σ Maps from domain of (states, states) to range of letters. Renaming function to λ (Lamda) Σ(q0, q1) (q2, q3) (q1, q3) a Dr. Hussien M. Sharaf 5 b c Allows more than one link from domain to codomain Not recommended
  • 6. How does FA work? 1. Starts from a start state. 2. Loop Reads a letters from the input 3. Until input string finishes 4. If the current state is a final state then Input string is accepted. 5. Else Input string is NOT accepted.  But how can FA be designed and represented? Dr. Hussien M. Sharaf 6
  • 7. Representation of FA: Graph  States= nodes  Starting state denoted by –  Final state(s) denoted by +  Transition function =directed arrows connecting states.  Build an FA for RE “a*b(a+b)*” Dr. Hussien M. Sharaf S1 - + S2 b a a,b 7
  • 8. Representation of FA: Table Dr. Hussien M. Sharaf a b -s1 s1 s2 +s2 s2 s2 Rows = states input symbols Final states Indicated by “+” “-” sign for start state 8
  • 9. Example1.1  Build an FA that accepts only aab Dr. Hussien M. Sharaf S1 - S3 a S2 a b + S4 S5 b b a a,b a b S1 S2 S5 S2 S3 S5 S3 S5 S4 S4 S5 S5 9 a,b
  • 10. Example1.2  Build an FA that accepts only aab Dr. Hussien M. Sharaf S1 - S3 a S2 a b + S4 a b S1 S2 ? S2 S3 ? S3 ? ? S4 ? ? 10
  • 11. Ex2  (a+b)* Dr. Hussien M. Sharaf a, b ± 11
  • 12. FA accepting nothing 1. FA with no final states Dr. Hussien M. Sharaf a - a,b b 2. FA with disconnected graph. Start state does not have a path to the final state. a - a,b b + b 12
  • 13. Ex3  All words with even count of letters. ((a+b)(a+b))* Dr. Hussien M. Sharaf 13 1± 2 a, b a, b
  • 14. Ex4.1  All words that start with “a” a(a+b)* Dr. Hussien M. Sharaf 14 1- 2 b a 3 + a,b 1- 2b a 3 + a,b a,b Does not accept all inputs
  • 15. Ex4.2  All words that start with “a” a(a+b)* Dr. Hussien M. Sharaf 15 1- 2b a 3 + a,b a,b Special accept state for string “a”, might give better performance in hardware implementation
  • 16. Ex5  All words that start with triple letter (aaa+bbb)(a+b)* Dr. Hussien M. Sharaf 16 1- 2a 3 a,b 4 b 5 b 6+ b a a
  • 17. Ex6  {aa, ba, baba, aaaa, bbba, abba, aaabaa, …}  All words with even count of letters and ends with “a”. (a+b)a ((a+b)a (b(a+b)a)* )* Dr. Hussien M. Sharaf 17 - a,b + a,b 5 b a a,b
  • 18. Ex7  {aa, ba, baba, aaaa, ab, bb, bababa, aaba, …}  All words with even count of letters having “a” in an even position from the start, where the first letter is letter number one. (a+b)a((a+b)a)* Dr. Hussien M. Sharaf 18 - a,b
  • 19. Ex8 Cohen 2nd edition page 63  Consider the following FA: Dr. Hussien M. Sharaf 19 •Whenever aa exists, the first “a” must take us to state 4 or state 2. •Either way, the next a takes us to state 4. Similar situation with “bb”. In summary: this FA accepts strings that have a double letter in them. (a + b)*(aa + bb)(a + b)*
  • 20. Ex9 Cohen 2nd edition page 64  Consider the following FA: Dr. Hussien M. Sharaf 20 •Accepts all words with b as the third letter and reject all other words. •A word that has fewer than three letters fails. RE1: (aab + abb + bab + bbb)(a + b)* OR :(a + b)(a + b)(b)(a + b)* = (a + b)2 b (a + b)* Notice that this last formula is not strictly speaking a regular expression, since it uses the symbol “2”
  • 21. Have you see any memory? Ex10  All strings that end in ab.  Do we need a memory to remember the last two letters? Dr. Hussien M. Sharaf 21 - a b … … …… + a b a b a b b b b b a
  • 22. Ex11  Even-Even :  All the words that end in state 3 have an even number of b's but an odd number of a's.  All words that end in state 4 have an odd number of a's and an odd number of b's.  Any EVEN-EVEN words must end in state 1 and be accepted. Dr. Hussien M. Sharaf 22
  • 23. Dr. Hussien M. Sharaf 23 Automaton CPU input memory output memory Program memory temporary memory Automaton
  • 24. Dr. Hussien M. Sharaf 24 Finite Automaton Input String Output String Finite Automaton
  • 25. Dr. Hussien M. Sharaf 25 Different Kinds of Automata Automata are distinguished by the temporary memory: • Finite Automata: no temporary memory • Pushdown Automata: stack • Turing Machines: random access memory
  • 26. Dr. Hussien M. Sharaf 26 Finite Automata Pushdown Automata Turing Machine Power of Automata
  • 27. 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 union {Λ} 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) Dr. Hussien M. Sharaf 27
  • 28. 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.
  • 29. 29 1q 2q 3q a a a 0q }{aAlphabet = 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. Dr. Hussien M. Sharaf
  • 30. 30 1q 2q 3q a a a 0q Two choices }{aAlphabet = NFA Dr. Hussien M. Sharaf
  • 31. 31 No transition 1q 2q 3q a a a 0q Two choices No transition }{aAlphabet = NFA Dr. Hussien M. Sharaf
  • 32. 32 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 NFA Dr. Hussien M. Sharaf
  • 33. 33 a a 0q 1q 2q 3q a a Acceptance Example 1 a NFA Dr. Hussien M. Sharaf
  • 34. 34 a a 0q 1q 2q a a a NFA Dr. Hussien M. Sharaf 3q
  • 35. 35 a a 0q a a a NFA Dr. Hussien M. Sharaf 3q “reject” 2q “accept” 1q
  • 36. 36 aa is accepted by the NFA: 0q 1q 2q 3q a a a “accept” 0q 1q 2q a a a 3q “reject” because this computation accepts aa this computation is ignored NFA Dr. Hussien M. Sharaf
  • 37. Dr. Hussien M. Sharaf 37 An NFA rejects a string: if there is no computation of the NFA that accepts the string. • All the input is consumed and the automaton is in a non final state • The input cannot be consumed (indecidable input) OR For each computation: NFA
  • 38. 38 a is rejected by the NFA: 0q 1q 2q a a a 3q “reject” 0q 1q 2q a a a 3q “reject” All possible computations lead to rejection NFA Dr. Hussien M. Sharaf
  • 39. 39 aaa is rejected by the NFA: 0q 1q 2q 3q a a a “reject” 0q 1q 2q a a a 3q “reject” All possible computations lead to rejection NFA Dr. Hussien M. Sharaf
  • 40. 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. Assignment 4  Proof that NFA and DFA are equivalent. Constructive type of proofs might be the most appropriate. Be formal and simple. Don’t exceed 2-3 slides. You might study the proof from “Sipser” book or “Models Of Computation”. Your answer might be delivered in form of slides to Eng. Eman“e.hossny@fci-cu.edu.eg” and CC to my email dr.sharaf@from-masr.com. You will present your slides in 5-7 minutes. Dr. Hussien M. Sharaf 41
  • 42. Thank you Dr. Hussien M. Sharaf 42