Professional Documents
Culture Documents
VENKATESH
Senior Professor, Dept. of CSE
AIET, Moodbidri
MODULE 1 SYLLABUS
• Introduction to Automata Theory: Central Concepts of
Automata theory, Deterministic Finite Automata (DFA), Non-
Deterministic Finite Automata (NFA), Epsilon- NFA, NFA to DFA
Conversion, Minimization of DFA
• Introduction to Compiler Design: Language Processors,
Phases of Compilers.
Alternate description:
{x01y | x and y are any strings of 0’s and 1’s}
q0 q1 q2
Write a transition diagram for DFA to accept a binary string
that contains 01 anywhere in the binary string.
Start q0 q1 q2
Write a transition diagram for DFA to accept a binary string
that contains 01 anywhere in the binary string.
Start q0 0 q1 1 q2
Write a transition diagram for DFA to accept a binary string
that contains 01 anywhere in the binary string.
1 0 0, 1
Start q0 0 q1 1 q2
Exercise to the Students
• Draw the Transition diagram to recognize the
binary string that ended with 01
Exercise to the Students
• Draw the Transition diagram to recognize the
binary string that ended with 01
Start q0 0 q1 1 q2
Exercise to the Students
• Draw the Transition diagram to recognize the
binary string that ended with 01
1 0
Start q0 0 q1 1 q2
Exercise to the Students
• Draw the Transition diagram to recognize the
binary string that ended with 01
1 0
0
Start q0 0 q1 1 q2
1
You may reposition the states
• After repositioning, you may get the Transition diagram
as shown below
1
Start 1
q0 q2
0 q1 1
0 0
Transition Tables
• It is a conventional tabular representation of a
transition function Ꟙ that takes two arguments and
returns a value.
• Rows of the table represents the states in the
transition diagram.
• Columns represents the input symbols. The entry
corresponds to the state q and the column
corresponds to the input a, is a state Ꟙ(q, a).
Write a transition table for accepting the binary string
containing 01 anywhere in the binary string
1 0 0, 1
Start q0 0 q1 1 q2
0 1
q0
q1
*q2
Write a transition table for accepting the binary string
containing 01 anywhere in the binary string
1 0 0, 1
Start q0 0 q1 1 q2
0 1
q0 q1 q0
q1 q1 q2
*q2 q2 q2
Extending the Transition Function to Strings
• If Ꟙ is our transition function, then the extended transition
function constructed from Ꟙ will be called ^
Ꟙ
• The extended transition function is a function that takes a
state q and a string w and returns a state p.
• The state p is the state that the automaton reaches when
starting in state q and processing the sequence of inputs w.
^
Defining Ꟙ by induction on the length of the input string
^
• Basis: Ꟙ(q, ε) = q. That is, if we are in state q and read no
inputs then we are still in state q.
• Induction: Suppose w is a string of the form xa; that is a is
last symbol of w, and x is the string consisting of all symbol in
w except last symbol. Then
^ ^
Ꟙ(q, w) = Ꟙ( Ꟙ (q, x), a)
Suppose that Ꟙ ^(q, w) is the transition from
^ (q, x) = p. Then Ꟙ
state p on input a, the last symbol of w. That is,
^ (q, w) = Ꟙ(p, a)
Ꟙ
Example: Design a DFA to accept the language
L = {w | w is of even length and begins with 01}
• This automaton needs to remember whether the string seen so far started with
01. It also needs to keep track the length of the string. So, it consists of five states
could be interpreted as follows:
• q0: The initial State.
• q1: The state entered on reading 0 in the state q0.
• q2: The DFA enters this state whenever the substring seen so far starts with 01 and
is even length.
• q3: The DFA enters this state whenever the substring seen so far starts with 01 and
is odd length.
• q4: The DFA enters this state whenever the string begins with 1 or it reads a
symbol 1 in q1.
Write the Transition Diagram for the same
Write the Transition Diagram for the same
Start 0 1
q0 q1 q2 q3
q4
Write the Transition Diagram for the same
Start 0 1 0, 1
q0 q1 q2 q3
1 0 0, 1
q4
Write the Transition Diagram for the same
Start 0 1 0, 1
q0 q1 q2 q3
1 0 0, 1
q4
Write a Transition Table
for this DFA
^
Ꟙ transition
Construct Extended Transition Function from its
function Ꟙ for the string 011101
^Ꟙ(q , ε) = q
0 0
^
Ꟙ (q , 0) = Ꟙ( ^
Ꟙ (q , ε), 0) = q
0 0 1
^
Ꟙ(q0, 01) = Ꟙ( ^Ꟙ(q0, 0), 1) = Ꟙ(q1, 1) = q2
^ ^
Ꟙ(q0, 011) = Ꟙ( Ꟙ (q0, 01), 1) = Ꟙ(q2, 1) = q3
^ (q
Ꟙ 0 , 0111) = Ꟙ( ^
Ꟙ(q0, 011), 1) = Ꟙ(q3, 1) = q2
^ (q , 01110) = Ꟙ( ^Ꟙ (q , 0111), 0) = Ꟙ(q , 0) = q
Ꟙ 0 0 2 3
^ (q , 011101) = Ꟙ( ^Ꟙ(q , 01110), 1) = Ꟙ(q , 0) = q
Ꟙ 0 0 3 2
Another Example: Write a DFA to accept all
Binary strings with length three or more that
does not contain 110
• The set of all strings such that containing either 101, or 110 as substring.
• The set of all strings such that every 1 is followed immediately by 00
• The set of all strings containing exactly two occurrences of 10
Epsilon–NFA (ε–NFA)
• NFA with ε transaction is known as ε–NFA.
• Example: Write NFA to accept signed integer number
• Examples for Signed integer number are:
+12, -54, 23
Formal Definition of ε-NFA
Formally we represent a ε-NFA A by A = {Q, Ʃ, Ꟙ, q0, F}
Where
• Q is a Finite Set of States
• Ʃ is a finite set of input symbols
• Q0 is a member of Q, is the start state.
• F is a subset of Q, is the set of final (or accepting) states.
• Ꟙ is the transition function. It is a function that takes a state in Q and an input
symbol in Ʃ U {ε} as arguments and returns a subset of Q. The difference
between DFA and NFA is in the type of value that Ꟙ returns a set of states in the
case of NFA and a single state in case of DFA.
Formal Definition of ε-NFA
Formally we represent a ε-NFA A by A = {Q, Ʃ, Ꟙ, q0, F}
Where
• Q is a Finite Set of States
• Ʃ is a finite set of input symbols
• Q0 is a member of Q, is the start state.
• F is a subset of Q, is the set of final (or accepting) states.
• Ꟙ is the transition function. It is a function that takes a state in Q and an input
symbol in Ʃ U {ε} as arguments and returns a subset of Q. The difference
between DFA and NFA is in the type of value that Ꟙ returns a set of states in the
case of NFA and a single state in case of DFA.
Epsilon Closure (ε Closure)
• The ε closure(P) is a set of states which are reachable
from state P on ε-transitions.
• ε-closure (P) = P, where P ∈ Q
• If there exists ε-closure (P) = {q} and 𝛿(q, ε) =r then, ε-
closure (P) = {q, r}
Example: Find ε-closure for the following Non-
deterministic finite automata (NFA) with epsilon.
• Solution:
• ε-closure (q0)= {q0,q1,q2}
• self state+ ε-reachable states.
• ε-closure (q1)= { q1,q2}
• q1 is self-state and q2 is a state obtained from q1 with epsilon input.
• ε-closure (q2)= {q2}
Minimization of DFA
• DFA minimization stands for converting a given DFA to its
equivalent DFA with minimum number of states.
• DFA minimization is also called as Optimization of DFA and
uses partitioning algorithm.
• DFA minimization is the task of transforming a given
Deterministic Finite Automaton (DFA) into an equivalent DFA
that has a minimum number of states. Here, two DFAs are
called equivalent if they recognize the same regular language.
Equivalence of States
• If two distinct states say p and q are equivalent, then we can replace
these two states by one single state that behaves like both p and q.
• We say that State p and state q are equivalent if for all strings w,
^ ^
Ꟙ (p, w) is an accepting state if and only if Ꟙ (q, w)is an accepting state
If the two states p and q are not equivalent, then we say p and q are
distinguishable.
Consider this Example
1 q4 1 q5 0, 1
q3
0
0 0 1 1
Start q 1 q1 0 q2 0
0
• In State q1, it exhibits same behavior for every input string as in state q2 and q4.
So, q1, q2, and q4 are non distinguishable states. These states are called as
equivalent states. Similarly, q0 and q3 are non distinguishable states.
Identify the Non Distinguishable States in the following Automata
Identify the Non Distinguishable States in the following Automata
B X
C X X
D X X X
E X X X
F X X X X
G X X X X X X
A B C D E F
Here,
C and E are Equivalent (non-distinguishable states)
D and F are Equivalent (non-distinguishable states)
Testing Equivalence of Regular Languages
Here ,
F.S represents -> Final State.
I.S represents -> Intermediate State
(Non-Final State)
0
0 0, 1