SlideShare a Scribd company logo
1 of 34
Deterministic
Finite Automata
COMPSCI 102 Lecture 2
Let me show you a
machine so simple
that you can
understand it in less
than two minutes
Steven Rudich:
www.cs.cmu.edu/~rudich
0
0,1
0
0
1
1
1
0111 111
11
1
The machine accepts a string if the process
ends in a double circle
Steven Rudich:
www.cs.cmu.edu/~rudich
0
0,1
0
0
1
1
1
The machine accepts a string if the process
ends in a double circle
Anatomy of a Deterministic Finite
Automaton
states
states
q0
q1
q2
q3
start state (q0)
accept states (F)
Steven Rudich:
www.cs.cmu.edu/~rudich
Anatomy of a Deterministic Finite
Automaton
0
0,1
0
0
1
1
1
q0
q1
q2
q3
The alphabet of a finite automaton is the set
where the symbols come from:
The language of a finite automaton is the set of
strings that it accepts
{0,1}
Steven Rudich:
www.cs.cmu.edu/~rudich
0,1
q0
L(M) = All strings of 0s and 1s

The Language of Machine M
Steven Rudich:
www.cs.cmu.edu/~rudich
q0 q1
0 0
1
1
L(M) = { w | w has an even number of 1s}
Steven Rudich:
www.cs.cmu.edu/~rudich
An alphabet Σ is a finite set (e.g., Σ = {0,1})
A string over Σ is a finite-length sequence of
elements of Σ
For x a string, |x| is the length of x
The unique string of length 0 will be denoted by ε
and will be called the empty or null string
Notation
A language over Σ is a set of strings over Σ
Steven Rudich:
www.cs.cmu.edu/~rudich
Q is the set of states
Σ is the alphabet
 : Q  Σ → Q is the transition function
q0  Q is the start state
F  Q is the set of accept states
A finite automaton is a 5-tuple M = (Q, Σ, , q0, F)
L(M) = the language of machine M
= set of all strings machine M accepts
Steven Rudich:
www.cs.cmu.edu/~rudich
Q = {q0, q1, q2, q3}
Σ = {0,1}
 : Q  Σ → Q transition function*
q0  Q is start state
F = {q1, q2}  Q accept states
M = (Q, Σ, , q0, F) where
 0 1
q0 q0 q1
q1 q2 q2
q2 q3 q2
q3 q0 q2
*
q2
0
0,1
0
0
1
1
1
q0
q1
q3
M
Steven Rudich:
www.cs.cmu.edu/~rudich
q q00
1 0
1
q0 q001
0 0 1
0,1
Build an automaton that accepts all and only
those strings that contain 001
Steven Rudich:
www.cs.cmu.edu/~rudich
A language is regular if it is
recognized by a deterministic finite
automaton
L = { w | w contains 001} is regular
L = { w | w has an even number of 1s} is regular
Steven Rudich:
www.cs.cmu.edu/~rudich
Union Theorem
Given two languages, L1 and L2, define the
union of L1 and L2 as
L1  L2 = { w | w  L1 or w  L2 }
Theorem: The union of two regular
languages is also a regular language
Steven Rudich:
www.cs.cmu.edu/~rudich
Theorem: The union of two regular
languages is also a regular language
Proof Sketch: Let
M1 = (Q1, Σ, 1, q0, F1) be finite automaton for L1
and
M2 = (Q2, Σ, 2, q0, F2) be finite automaton for L2
We want to construct a finite automaton
M = (Q, Σ, , q0, F) that recognizes L = L1  L2
1
2
Steven Rudich:
www.cs.cmu.edu/~rudich
Idea: Run both M1 and M2 at the same time!
Q = pairs of states, one from M1 and one from M2
= { (q1, q2) | q1  Q1 and q2  Q2 }
= Q1  Q2
Steven Rudich:
www.cs.cmu.edu/~rudich
Theorem: The union of two regular
languages is also a regular language
q0 q1
0
0
1
1
p0 p1
1
1
0
0
Steven Rudich:
www.cs.cmu.edu/~rudich
q0,p0 q1,p0
1
1
q0,p1 q1,p1
1
1
0
0
0
0
Automaton for Union
Steven Rudich:
www.cs.cmu.edu/~rudich
q0,p0 q1,p0
1
1
q0,p1 q1,p1
1
1
0
0
0
0
Automaton for Intersection
Steven Rudich:
www.cs.cmu.edu/~rudich
Theorem: The union of two regular
languages is also a regular language
Corollary: Any finite language is regular
Steven Rudich:
www.cs.cmu.edu/~rudich
The Regular Operations
Union: A  B = { w | w  A or w  B }
Intersection: A  B = { w | w  A and w  B }
Negation: A = { w | w  A }
Reverse: AR = { w1 …wk | wk …w1  A }
Concatenation: A  B = { vw | v  A and w  B }
Star: A* = { w1 …wk | k ≥ 0 and each wi  A }
Steven Rudich:
www.cs.cmu.edu/~rudich
Regular Languages Are
Closed Under The Regular
Operations
We have seen part of the proof for Union.
The proof for intersection is very similar. The
proof for negation is easy.
Input: Text T of length t, string S of length n
The “Grep” Problem
Problem: Does string S appear inside text T?
a1, a2, a3, a4, a5, …, at
Naïve method:
Cost: Roughly nt comparisons
Automata Solution
Build a machine M that accepts any string
with S as a consecutive substring
Feed the text to M
Cost:
As luck would have it, the Knuth, Morris, Pratt
algorithm builds M quickly
t comparisons + time to build M
Grep
Coke Machines
Thermostats (fridge)
Elevators
Train Track Switches
Lexical Analyzers for Parsers
Real-life Uses of DFAs
Are all
languages
regular?
i.e., a bunch of a’s followed by an equal
number of b’s
Consider the language L = { anbn | n > 0 }
No finite automaton accepts this language
Can you prove this?
anbn is not regular.
No machine has
enough states to
keep track of the
number of a’s it
might encounter
That is a fairly weak
argument
Consider the following
example…
L = strings where the # of occurrences of the
pattern ab is equal to the number of
occurrences of the pattern ba
Can’t be regular. No machine has
enough states to keep track of the
number of occurrences of ab
M accepts only the strings with an
equal number of ab’s and ba’s!
b
b
a
b
a
a
a
b
a
b
Let me show you a
professional strength proof
that anbn is not regular…
Pigeonhole principle:
Given n boxes and m > n
objects, at least one box
must contain more than
one object
Letterbox principle:
If the average number of
letters per box is x, then
some box will have at least
x letters (similarly, some
box has at most x)
Theorem: L= {anbn | n > 0 } is not regular
Proof (by contradiction):
Assume that L is regular
Then there exists a machine M with k states
that accepts L
For each 0  i  k, let Si be the state M is in
after reading ai
i,j  k such that Si = Sj, but i  j
M will do the same thing on aibi and ajbi
But a valid M must reject ajbi and accept aibi
Deterministic Finite
Automata
• Definition
• Testing if they accept a string
• Building automata
Regular Languages
• Definition
• Closed Under Union,
Intersection, Negation
• Using Pigeonhole Principle to
show language ain’t regular
Here’s What
You Need to
Know…

More Related Content

Similar to lecture02.ppt

F_Autómatas_MIT_2010--------------------
F_Autómatas_MIT_2010--------------------F_Autómatas_MIT_2010--------------------
F_Autómatas_MIT_2010--------------------
MIGUELANGEL2672
 

Similar to lecture02.ppt (20)

Automata Theory
Automata TheoryAutomata Theory
Automata Theory
 
practice-final-soln.pdf
practice-final-soln.pdfpractice-final-soln.pdf
practice-final-soln.pdf
 
Lecture7x.ppt
Lecture7x.pptLecture7x.ppt
Lecture7x.ppt
 
Lecture1.pptxjendfkdmdmmdmmedhf bf fbbd ed
Lecture1.pptxjendfkdmdmmdmmedhf bf fbbd edLecture1.pptxjendfkdmdmmdmmedhf bf fbbd ed
Lecture1.pptxjendfkdmdmmdmmedhf bf fbbd ed
 
RegularLanguageProperties.pptx
RegularLanguageProperties.pptxRegularLanguageProperties.pptx
RegularLanguageProperties.pptx
 
Dfa h11
Dfa h11Dfa h11
Dfa h11
 
Teori automata lengkap
Teori automata lengkapTeori automata lengkap
Teori automata lengkap
 
lecture11.ppt
lecture11.pptlecture11.ppt
lecture11.ppt
 
Deterministic finite automata
Deterministic finite automata Deterministic finite automata
Deterministic finite automata
 
Introduction to the Theory of Computation, Winter 2003 A. Hevia and J. Mao S...
 Introduction to the Theory of Computation, Winter 2003 A. Hevia and J. Mao S... Introduction to the Theory of Computation, Winter 2003 A. Hevia and J. Mao S...
Introduction to the Theory of Computation, Winter 2003 A. Hevia and J. Mao S...
 
Program on Quasi-Monte Carlo and High-Dimensional Sampling Methods for Applie...
Program on Quasi-Monte Carlo and High-Dimensional Sampling Methods for Applie...Program on Quasi-Monte Carlo and High-Dimensional Sampling Methods for Applie...
Program on Quasi-Monte Carlo and High-Dimensional Sampling Methods for Applie...
 
Parametrized Model Checking of Fault Tolerant Distributed Algorithms by Abstr...
Parametrized Model Checking of Fault Tolerant Distributed Algorithms by Abstr...Parametrized Model Checking of Fault Tolerant Distributed Algorithms by Abstr...
Parametrized Model Checking of Fault Tolerant Distributed Algorithms by Abstr...
 
F_Autómatas_MIT_2010--------------------
F_Autómatas_MIT_2010--------------------F_Autómatas_MIT_2010--------------------
F_Autómatas_MIT_2010--------------------
 
Inner product
Inner productInner product
Inner product
 
QB104541.pdf
QB104541.pdfQB104541.pdf
QB104541.pdf
 
Finite automata
Finite automataFinite automata
Finite automata
 
Mod 2_RegularExpressions.pptx
Mod 2_RegularExpressions.pptxMod 2_RegularExpressions.pptx
Mod 2_RegularExpressions.pptx
 
Mid semexam | Theory of Computation | Akash Anand | MTH 401A | IIT Kanpur
Mid semexam | Theory of Computation | Akash Anand | MTH 401A | IIT KanpurMid semexam | Theory of Computation | Akash Anand | MTH 401A | IIT Kanpur
Mid semexam | Theory of Computation | Akash Anand | MTH 401A | IIT Kanpur
 
FLAT.pdf
FLAT.pdfFLAT.pdf
FLAT.pdf
 
Dfa
DfaDfa
Dfa
 

More from Joel Manio

More from Joel Manio (7)

DLL_TLE_sept.-4-8.docx
DLL_TLE_sept.-4-8.docxDLL_TLE_sept.-4-8.docx
DLL_TLE_sept.-4-8.docx
 
02-chapter-1.ppt
02-chapter-1.ppt02-chapter-1.ppt
02-chapter-1.ppt
 
History of computer .ppt
History of computer .pptHistory of computer .ppt
History of computer .ppt
 
sss-sickness-notification.pdf
sss-sickness-notification.pdfsss-sickness-notification.pdf
sss-sickness-notification.pdf
 
ProgrammingIntroduction.ppt
ProgrammingIntroduction.pptProgrammingIntroduction.ppt
ProgrammingIntroduction.ppt
 
10 ssp Activity simple Payroll.pptx
10 ssp Activity simple Payroll.pptx10 ssp Activity simple Payroll.pptx
10 ssp Activity simple Payroll.pptx
 
10 ssp Activity simple Payroll.pptx
10 ssp Activity simple Payroll.pptx10 ssp Activity simple Payroll.pptx
10 ssp Activity simple Payroll.pptx
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Recently uploaded (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps Productivity
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern Enterprise
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Choreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringChoreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software Engineering
 

lecture02.ppt