SlideShare a Scribd company logo
1 of 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

More Related Content

What's hot

Nondeterministic Finite Automata
Nondeterministic Finite AutomataNondeterministic Finite Automata
Nondeterministic Finite Automata
Adel Al-Ofairi
 
Theory of computing
Theory of computingTheory of computing
Theory of computing
Ranjan Kumar
 

What's hot (20)

Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Pushdown Automata Theory
Pushdown Automata TheoryPushdown Automata Theory
Pushdown Automata Theory
 
Minimization of DFA
Minimization of DFAMinimization of DFA
Minimization of DFA
 
Intro automata theory
Intro automata theory Intro automata theory
Intro automata theory
 
Context free grammar
Context free grammar Context free grammar
Context free grammar
 
Nondeterministic Finite Automata
Nondeterministic Finite AutomataNondeterministic Finite Automata
Nondeterministic Finite Automata
 
Ch2 finite automaton
Ch2 finite automatonCh2 finite automaton
Ch2 finite automaton
 
Context free grammar
Context free grammarContext free grammar
Context free grammar
 
Automata
AutomataAutomata
Automata
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
 
Lecture: Regular Expressions and Regular Languages
Lecture: Regular Expressions and Regular LanguagesLecture: Regular Expressions and Regular Languages
Lecture: Regular Expressions and Regular Languages
 
Regular Expression in Compiler design
Regular Expression in Compiler designRegular Expression in Compiler design
Regular Expression in Compiler design
 
Lecture 8
Lecture 8Lecture 8
Lecture 8
 
Automata theory
Automata theoryAutomata theory
Automata theory
 
TOC 2 | Deterministic Finite Automata
TOC 2 | Deterministic Finite AutomataTOC 2 | Deterministic Finite Automata
TOC 2 | Deterministic Finite Automata
 
Theory of computing
Theory of computingTheory of computing
Theory of computing
 
AUTOMATA THEORY - SHORT NOTES
AUTOMATA THEORY - SHORT NOTESAUTOMATA THEORY - SHORT NOTES
AUTOMATA THEORY - SHORT NOTES
 
Kleene's theorem
Kleene's theoremKleene's theorem
Kleene's theorem
 
4.6 halting problem
4.6 halting problem4.6 halting problem
4.6 halting problem
 
TOC 5 | Regular Expressions
TOC 5 | Regular ExpressionsTOC 5 | Regular Expressions
TOC 5 | Regular Expressions
 

Similar to Theory of computation Lec3 dfa

RegularLanguageProperties [Autosaved].pptx
RegularLanguageProperties [Autosaved].pptxRegularLanguageProperties [Autosaved].pptx
RegularLanguageProperties [Autosaved].pptx
RaviAr5
 
Finite State Machines with Output
Finite State Machines with OutputFinite State Machines with Output
Finite State Machines with Output
Mustafa Saeed
 
Nondeterministic Finite Automat
Nondeterministic Finite AutomatNondeterministic Finite Automat
Nondeterministic Finite Automat
Adel Al-Ofairi
 
Csr2011 june17 14_00_bulatov
Csr2011 june17 14_00_bulatovCsr2011 june17 14_00_bulatov
Csr2011 june17 14_00_bulatov
CSR2011
 

Similar to 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
 

More from 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 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
 

Recently uploaded

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Recently uploaded (20)

Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
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
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 

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