Cse303 Elements of The Theory of Computation: Professor Anita Wasilewska
Cse303 Elements of The Theory of Computation: Professor Anita Wasilewska
LECTURE 5
CHAPTER 2
FINITE AUTOMATA
1. Deterministic Finite Automata DFA
2. Nondeterministic Finite Automata NDFA
3. Finite Automata and Regular Expressions
4. Languages that are Not Regular
5. State Minimization
6. Algorithmic Aspects of Finite Automata
CHAPTER 2
PART 1: Deterministic Finite Automata DFA
Operation of DFA
O6 When the process stops the DFA indicates its approval
or disapproval of the string by means of the final state
O7 If the process stops while being in the final state, the
string is accepted
O8 If the process stops while not being in the final state,
the string is not accepted
as an alphabet
s K is the initial state
F K is the set of final states
is a function
: K K
called the transition function
We usually use different symbols for K , , i.e. we have that
K =
DFA Definition
Definition revisited
A Deterministic Finite Automata is a quintuple
M = (K , , , s , F )
where
K is a finite set of states
K , because s K
as an alphabet
can be - case to consider
s K is the initial state
F K is the set of final states
F can be - case to consider
is a function
: K K
called the transition function
Transition Function
Given DFA
M = (K , , , s , F )
where
: K K
Let
(q, ) = q0 for q, q0 K ,
means: the automaton M in the state q reads and
moves to a state q0 K , which is uniquely determined by
state q and just read
Configuration
In order to define a notion of computation of M on an input
string w we introduce first a notion of a configuration
Definition
A configuration is any tuple
(q, w ) K
where q K represents a current state of M and w is
unread part of the input
Picture
Transition Relation
Definition
The set of all possible configurations of M = (K , , , s , F )
is just
K = {(q, w ) : q K , w }
We define move of an automaton M i in terms of a transition
relation
`M
The transition relation acts between two configurations
and hence `M is a certain binary relation defined on
K , i.e.
`M (K )2
Formal definition follows
Transition Relation
Definition
Given M = (K , , , s , F )
A binary relation
`M (K )2
is called a transition relation when for any
q, q0 K , w1 , w2 the following holds
(q, w1 ) `M (q0 , w2 )
if and only if
1. w1 = w2 , for some (M looks at )
2. (q, ) = q0 (M moves from q to q reading in w1 )
Transition Relation
Definition Transition relation short definition
Given M = (K , , , s , F )
For any q, q0 K ,
, w
(q, w ) `M (q0 , w )
if and only if
(q, ) = q0
Idea of Computation
We use the transition relation to define a move of M along a
given input, i.e. a given w
Such a move is called a computation
Example
Given M such that K = {s , q} and let `M be a transition
relation such that
Idea of Computation
Given a a computaion
n1
(q1 , w1 ) = (q, w ),
(qi , wi ) `M (qi +1 , wi +1 )
for
i = 1, 2, . . . n 1
Words Accepted by M
Definition
A word w is accepted by M = (K , , , s , F )
if and only if there is computation
(s , w ), (q2 , w2 ), . . . , (q, e )
and q F
Words Accepted by M
In Plain Words:
A word w is accepted by M = (K , , , s , F )
if and only if
there is a computation such that
1. starts with the word w and M in the initial state ,
2. ends when M is in a final state, and
3. the whole word w has been read
Language Accepted by M
Definition
We define the language accepted by M as follows
L (M ) = {w :
w is accepted by M }
i.e.
L (M ) = {w : (s , w ) `M . . . `M (q, e ) for some q F }
Examples
Example 1
Let M = (K , , , s , F )
where
K = {q0 , q1 },
= {a , b },
s = q0 ,
F = {q0 }
Examples
Solution
We must evaluate computation that starts with the
configuration (q0 , ababb ) as q0 = s
(q0 , ababb ) `M
(q0 , babb ) `M
(q1 , abb ) `M
(q1 , bb ) `M
use (q0 , a ) = q0
use (q0 , b ) = q1
use (q1 , a ) = q1
use (q1 , b ) = q0
(q0 , b ) `M
use (q0 , b ) = q1
(q1 , e ) `M
Examples
Example 2
Let M1 = (K , , , s , F ) for all components defined as in
M from Example 1, except that we take now F = {q0 , q1 }
We remind that
Definition
L (M ) = {w : (s , w ) `M (q, e ) for some q F }
We now bring back the general notion of a path in a binary
relation R (Lecture 2) and its reflexive, transitive closure R
(Lecture 3)
It follows directly from these definitions that `M is just a
shorthand notation for the computation
(s , w ), (q2 , w2 ), . . . , (qn , e )
Path in R
Example
Example
Let M = (K , , , s , F ) be automaton from our Example
1, i.e. we have
K = {q0 , q1 },
= {a , b },
s = q0 ,
F = {q0 }
Example
We evaluate
General remark
To define or to give an example of
M = (K , , , s , F )
means that one has to specify all its components
K , , , s , F
We usually use different symbols for K , , i.e. we have that
K =
Exercise
Given = {a , b } and K == {q0 , q1 }
1. Define 3 automata M
2. Define an automaton M, such that L (M ) =
3. How many automata M can one define?
Exercise
1. Here are 3 automata M1 M3
M1 : M1 = ( K = {q0 , q1 }, = {a , b }, , s = q0 , F = {q0 })
Exercise
2. Define an automaton M, such that L (M ) =
Answer: The automata M2 is such that L (M2 ) = as there
is no computation that would start at initial state q0 and
end in the final state q1 as in M2 we have that
(q0 , a ) = q0 , (q0 , b ) = q0 , so we will never reach the final
state q1
Here is another example:
Let M4 be defined as follows
M4 = ( K = {q0 , q1 }, = {a , b }, , s = q0 , F = )
Exercise
3. How many automata M can one define?
Observe that all of M must have = {a , b } and
K == {q0 , q1 } so they differ on the choices of
: K K
By Counting Functions Theorem we have 24 possible
choices for
They also can differ on the choices of final states F
There as many choices for final states as subsets of
K == {q0 , q1 }, i.e. 22 = 4
Additionally we have to count all combinations of choices of
with choices of F
Challenge
1. Define an automata M with , such that L (M ) =
2. Define an automata M with , such that L (M ) =
3. Define an automata M with = such that L (M ) ,
4. Define an automata M with , such that L (M ) =
5. Prove that there always exist an automata M such that
L (M ) =
A Simple Problem
Problem
Given M = (K , , , s , F )
diagram
A Simple Problem
Given the diagram
Components are: M = (K , , , s , F )
= {a , b }, K = {q0 , q1 , q2 },
for
A Simple Problem
2. Describe L (M ) as a regular expression, where
L (M ) = {w : (s , w ) `M (q, e ) for q F }
Lets look again at the diagram of M
DFA Theorem
DFA Theorem
For any DFA M = (K , , , s , F ),
e L (M )
if and only if
sF
TRAP States of M
Given a diagram of M
Remember that if you use the short diagram you must add
statement: plus trap states
Pattern Diagrams
Pattern Diagrams are very useful when we want to read
the language M directly out of the diagram
Lets look at M1 given by a diagram
Pattern Diagrams
The pattern diagram for our M is
Trap States
Why do we need trap states?
Lets take = {a , b } and let M be defined by a diagram
Short Problems
For all short problems presented here (and given on Quizzes
and Tests) you have to do the following
1. Decide and explain whether the diagram represents a
DFA or does not
2. List all components of M when it represents DFA
3. Describe L (M ) as a regular expression when it
represents DFA
Short Problems
Consider a diagram M1
(q0 , a ) = q1 , (q1 , a ) = q1
3. L (M1) = aa
Short Problems
Consider a diagram M2
Short Problems
Consider a diagram M3
Short Problems
Consider a diagram M4
Short Problems
Consider a diagram M5
Short Problems
Consider a diagram M6
Short Problems
Consider a diagram M7
1. Yes! it is DFA
Initial state exists and we can complete definition of by
adding a trap state as pictured below
Short Problems
Consider a diagram M8
3. L (M8) = aa
We chose to add one trap state but it is possible to add as
many as one wishes
Observe that L (M8) = L (M1) and M1, M8 are defined for
different alphabets
Two Problems
P1 Let = {a1 , a2 , . . . , a1025 , . . . , a2105 }
Draw a state diagram of M such that L (M ) = a1025( a1025 )
P2
1. Draw a state diagram of transition function given by
the table below
2. Give an example and automaton M with with this
3.
P1 Solution
P1
P1 Solution
Observe that we have a following
pattern for any
L (M ) = +
for any
= {}
P2 Solutions
P2
1. Draw a state diagram of transition function given by
the table below
2.
P2 Solution
Observe that the book example is only one of many possible
examples of automata we can define based on with the
following
State diagram:
P2 Examples
Example 1
Here is a full diagram of M1
L (M ) = (a b ) =
Observe that e L (M1) by the DFA Theorem and the states
q0 , q1 , q2 are trap states
P2 Examples
Example 2
Here is a full diagram of M1 from Example 1
L (M ) = (a b ) =
Observe that we can make all, or any of the states q0 , q1 , q2
as final states and they will still will remain the trap states
Definition
A trap state of a DFA automaton M is any of its states that
does not influence the language L(M ) of M
P2 Examples
Example 3
Here is a full diagram of M2
L (M ) =
Observe that F = and hence here is no computation that
would finish in a final state
More Problems
P3
Problems Solutions
P3
Problems Solutions
We complete the essential part following the fact that it can be
surrounded by proper elements on both sides and can be
repeated
Here is the diagram of M
More Problems
P4
More Problems
P4
More Problems
P5
More Problems
P5
Solution
More Problems
P6
More Problems
P6
More Problems
P7
More Problems
P7
Short Problems
SP1
Given an automaton M1
M1 = ( K = {q0 , q1 }, = {a , b }, , s = q0 , F = )
2.
3. Describe L(M1)
SP1 Solution
SP1
1.
2.
3.
L (M1) =
Short Problems
SP2
Given an automaton M2
M2 = ( K = {q0 , q1 }, = {a , b }, , s = q0 , F = {q1 })
2.
3.
Describe L(M2)
SP2 Solution
SP2
1.
L (M2) =
Short Problems
SP3
Given an automaton M3
M3 = (K = {q0 , q1 }, = {a , b }, , s = q0 , F = {q1 })
2.
3.
Describe L(M3)
SP3 Solution
SP3
1.
2.
3.
L (M3) = a b a ba (a ba ba b )
L (M3) = a ba (a ba ba b )
Short Problems
SP4 Given an automaton M4 = ( K , , , s , F ) for
K = {q0 , q1 , q2 , q3 }, = {a , b }, s = q0 , F = {q0 , q1 , q2 }
and defined by the table below
SP4 Solution
SP4
1.
SP4 Solution
SP4
1. Here is the short diagram
2. The language of M4 is
L (M4) = {w : neither aa nor bb is a substring of w }
Short Problems
SP5 Given an automaton M5 = ( K , , , s , F ) for
K = {q0 , q1 , q2 , q3 }, = {a , b }, s = q0 , F = {q1 }
and defined by the table below
SP5 Solution
SP5
1.
2.