0% found this document useful (0 votes)
3 views

AT Module 1 -Autosaved-.ppt

The document provides an overview of automata theory, focusing on finite automata as a mathematical model for recognizing regular languages. It explains key concepts such as alphabets, strings, language hierarchies, and the different classes of languages including regular and context-free languages. Additionally, it discusses the transition from finite state machines to more complex models like pushdown automata and Turing machines for recognizing more complex languages.

Uploaded by

shreyahv48
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

AT Module 1 -Autosaved-.ppt

The document provides an overview of automata theory, focusing on finite automata as a mathematical model for recognizing regular languages. It explains key concepts such as alphabets, strings, language hierarchies, and the different classes of languages including regular and context-free languages. Additionally, it discusses the transition from finite state machines to more complex models like pushdown automata and Turing machines for recognizing more complex languages.

Uploaded by

shreyahv48
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 119

AUTOMATA

THEORY
FINITE AUTOMATA AND FORMAL
LANGUAGE

Textbook:
Elaine Rich, Automata, Computability and
1.

Complexity, 1stEdition, Pearson Education, 2012 /


2013.
K L P Mishra, N Chandrasekaran, 3rd Edition, Theory
2.

of Computer Science, PhI, 2012.


A.M. Padma Reddy, Finite Automata and Formal
3.

Languages.(Refer to Problems )
INTRODUCTION TO
FINITE AUTOMATA
• Automata theory: It is the study of abstract machine
or computing devices.
• Abstract machine: Machine which are not
implemented using some formal notations. It is a
conceptual or theoretical model of a computer system
which really does not exists.
• Finite automata: It is the branch of automata
theory.
INTRODUCTION TO
FINITE AUTOMATA
• Finite automata :
It is a mathematical model which is used to study
the abstract machine or computing devices with the
input chosen from Σ (set alphabet).
Finite automata are computing devices that
accept/recognize regular languages and are used to
model operations of many systems we find in
practice.
Their operations can be simulated by a very simple
computer program.
INTRODUCTION TO
FINITE AUTOMATA
• Example: Electric on/off switch
• Consider an electric switch which has only two states
“off” and “on”.
• To start, if it is in off state, then pressing the button
changes it to the on state.
• If it is in on state, then pressing the button changes it
to the off state.

Push

Start
off on

Push
INTRODUCTION TO
FINITE AUTOMATA
? Example : lexical analyzer of compiler
? Job of this automata is to recognize the keyword then.

Start t h n
e
t th the then
INTRODUCTION TO
FINITE AUTOMATA
? Symbols used in FA

Symbols Meaning
A circle is used to represent a state. Here, q0 is
q0 a state of the machine.

q0 A circle with an arrow which is not originating


from any node represent start state of
machine.
q0 Two circle are used to represent a final state.
Here, q0 is a final state of the machine.
1
q0 q1 An Arrow with label 1 goes from state q0 to q1.
Indicates there is a transition from state q0 to
q1 on input symbol 1. Represented as δ(q0,1)=q1
INTRODUCTION TO
FINITE AUTOMATA
? Symbols used in FA

Symbols Meaning
An Arrow with label 0 starts and ends in q0.
Indicates the machine in state q0 on reading a
q0 0 0, it remains in same state q0 .Represented as δ
(q0,0)=q0

An Arrow with label 0,1 goes from state q0 to q1.


0,1 Indicates the machine in state q0 on reading a 0
q0 q1
or 1 enters into state q1. Represented as δ
(q0,0)=q1 δ(q0,1)=q1
THE CENTRAL CONCEPT OF
AUTOMATA THEORY
• The important definitions of terms:
• Alphabets: An alphabet is a finite, nonempty set of
symbols. The symbol Σ denotes the set of alphabet.
• Example
• Σ={0,1}, the binary alphabets.
• Σ={a, b, …..z}, the set of all lower-case letters.
• The set of all ASCII characters, or the set of all
printable ASCII characters.

• String (or word): is a finite sequence of symbols


chosen from the alphabet(Σ).
• Example
• 010101 is a string from the binary alphabet Σ={0,1}.
THE CENTRAL CONCEPT OF
AUTOMATA THEORY: FUNCTIONS
ON STRINGS
• Empty string is the string with zero occurrences of
symbols. Denoted by ε (pronounced as epsilon), is a string
that may be chosen from any alphabet whatsoever.
• Length of a string is the number of symbols in the string.
The length of a string u is denoted by |u|.
• Example : i) if u=011 then |u|=3.
ii) |ε| =0.
iii) εw=wε =w
• Concatenation of string: Let x and y be strings. Then xy
denotes the concatenation of x and y, i.e., the string formed
by making a copy of x and followed by a copy of y.
• Example: let x=“VV” and y=“CE” then xy=“VVCE”.
▪ Replication: For each string w and each natural
number i, the string wi is defined as:
▪ w0 = ε
▪ wi+1 = wi w
▪ For example:
▪ a3 = aaa
▪ (bye)2 = byebye
▪ a0 b3 = bbb
▪ Reversal: For each string w, the reverse of w, which
we will write wR, is defined as:
▪ if |w| = 0 then wR = w = ε
▪ if |w| ≥ 1 then Ǝa ϵ (Ǝu ϵ Σ*(w = ua)). (i.e., the
last character of w is a.) Then define wR = auR .
▪ Relations on Strings

▪ Substring: A string s is a substring of a string t iff s


occurs contiguously as part of t. For example:
▪ aaa is a substring of aaabbbaaa
▪ aaaaaa is not a substring of aaabbbaaa

▪ Proper Substring: A string s is a proper substring of


a string t iff s is a substring of t and s ≠t.
▪ Every string is a substring (although not a proper
substring) of itself. The empty string, ε , is a
substring of every string.
▪ Prefix: A string s is a prefix of t iff Ǝx ϵ Σ*(t = sx).
▪ A string s is a proper prefix of a string t iff s is a prefix of t
and s ≠ t. Every string is a prefix (although not a proper
prefix) of itself.
▪ The empty string, ε , is a prefix of every string. For
example, the prefixes of abba are: ε , a, ab, abb, abba.
▪ Suffix: A string s is a suffix of t iff Ǝx ϵ Σ* (t = xs).
▪ A string s is a proper suffix of a string t iff s is a suffix of t
and s ≠ t. Every string is a suffix (although not a proper
suffix) of itself.
▪ The empty string, ε , is a suffix of every string. For
example, the suffixes of abba are: ε , a, ba, bba, abba.
THE CENTRAL CONCEPT OF
AUTOMATA THEORY
• Powers of an Alphabet: denoted by Σk to be the set
of strings of length k, each of whose symbols is in Σ.
• Example:
• Note : Σ0 ={ε}, regardless of what alphabet Σ is. i.e., is
the only string whose length is 0.
• If Σ={0,1}, then
• Σ1 ={0,1}, set of strings of length 1.
• Σ2 ={00,01,10,11}, set of string of length 2.
• Σ3 ={000,001,010,011,100, 101, 110, 111}, set of
string of length 3 and so on.
THE CENTRAL CONCEPT OF
AUTOMATA THEORY
*
• Σ (Kleene closure): The set of all strings over an alphabet Σ. Denoted
by Σ* = Σ0 ᴜ Σ1 ᴜ Σ2 ᴜ......
• Example 1: let Σ ={0,1}. Then
• Σ* ={0,1}* ={ε ,0,1,00,01,10,11,000,001,100,……..}, which is the set of
strings of 0’s and 1’s of any length.
• Example 2: let Σ ={“a”, “bc”}. Then
• Σ* ={“a”, “bc”}* ={ε , “a”, “bc”, “aa”, “abc”, “bcbc”,“bca”……..},
which is the set of strings of a’ s and bc’s of any length.
• Σ+ (Kleene Plus): The set of all strings except the null string i.e., Σ0
={ε}over an alphabet Σ. Denoted by Σ+ = Σ1 ᴜ Σ2 ᴜ Σ3 ᴜ......
• Example 1: let Σ ={0,1}. Then
• Σ+ ={0,1}+ ={0,1,00,01,10,11,000,001,100,……..}, which is the set of
strings of 0’s and 1’s of any length except the null string.
• Note : Σ* = Σ+ + ε and Σ+ = Σ* - ε
THE CENTRAL CONCEPT OF
AUTOMATA THEORY
• Language: a set of all strings obtained from Σ* ,
where Σ is a particular alphabet. In other words, a
language is a subset Σ* of which is denoted by L ⊆ Σ* .
• Example :
1. A language of a string consisting of an equal
number of 0’s and 1’s can be represented as
{ε ,01,10,0011,1010,001011,……..}
2. The language of all strings consisting of “n” 0’s
followed by “n” 1’s, for some n>=0:
{ε ,01,0011,000111,00001111……..}
3. The set of binary numbers whose value is prime:
{10,11,101,111,1011,1001,…..}
THE CENTRAL CONCEPT OF
AUTOMATA THEORY
4. Σ* is a language for any alphabet Σ.
5. ϕ, the empty language, is a language over any
alphabet.
6. {ε}, the language consisting of only the empty string,
is also a language over any alphabet.
• Note: ϕ has no strings, ε has one string.
A LANGUAGE HIERARCHY
▪ Defining the Task: Language Recognition
▪ Assume that we are given:
▪ the definition of a language “L”
▪ a string “w”
▪ Then we must answer the question: “Is w in L?”
▪ This question is an instance of a more general class
that we will call decision problems.
▪ A decision problem is simply a problem that
requires a yes or no answer.
▪ The Power of Encoding
▪ Question: “Is w in L?”, is too limited to be useful.
▪ What about problems like multiplying numbers,
sorting lists, and retrieving values from a database?
▪ And what about real problems like air traffic control
or inventory management?
▪ Can our theory tell us anything interesting about them?
▪ The answer is yes and the key is encoding.
▪ Two categories:
▪ problems that are already stated as decision problems.
▪ problems that are not already stated as decision
problems.
▪ Problems that are already stated as decision
problems:
▪ For these, all we need to do is to encode the inputs
as strings and then define a language that contains
exactly the set of inputs for which the desired answer
is yes.
▪ Problems that are not already stated as decision
problems
▪ These problems may require results of any type.
▪ For these, we must first reformulate the problem
as a decision problem and then encode it as a
language recognition task.
▪ Notation <X, Y> to mean the encoding, into a single
string, of the two objects X and Y.
▪ Casting Problems as Decision Problems
▪ Problems that are not already stated as decision questions
can be transformed into decision questions.
▪ More specifically, they can be reformulated so that they
become language recognition problems.
▪ The idea is to encode, into a single string, both the inputs
and the outputs of the original problem P.
▪ So, for example, if P takes two inputs and produces one
result, we could construct strings of the form i1; i2; r.
▪ Then a string s = x; y; z is in the language L that
corresponds to P iff z is the result that P produces given the
inputs x and y.
A MACHINE-BASED HIERARCHY
OF LANGUAGE CLASSES
❖ The Regular Languages
▪ The first model is the finite state machine or FSM.
▪ The input to an FSM is a string fed to it one character at
a time, left to right.
▪ The FSM has a start state with an unlabeled arrow
leading to it, and some number (zero or more) of
accepting states, which is represented by double circles.
▪ The FSM starts in its start state.
▪ As each character is read, the FSM changes state based
on the transitions.
▪ If an FSM M accepts after reading the last character of
some input string s, then M accepts s. Otherwise, it
rejects it.
Figure shows a simple FSM that accepts
strings of a’s and b’s, where all a’s come
before all b’s.

▪ Our example FSM stays in state 1 as long as it is reading a’s.


▪ When it sees a ‘b’, it moves to state 2, where it stays as long
as it continues seeing b’s.
▪ Both state 1 and state 2 are accepting states.
▪ But if, in state 2, it sees an a, it goes to state 3, a
nonaccepting state, where it stays until it runs out of input.
▪ So, for example, this machine will accept aab, aabbb, and bb.
It will reject ba.
▪ the class of languages that can be accepted by some FSM
regular
❖ The Context-Free Languages
▪ Some languages that are not regular.
▪ Consider, for example, Bal, the language of balanced
▪ parentheses.
▪ Bal contains strings like (()) and ()(); it does not
contain strings like ()))(.
▪ Another example: AnBn = {anbn : n ≥0}
▪ In any string in AnBn, all the a’s come first and the
number of a’s equals the number of b’s.
▪ FSM cannot remember n.
▪ Solution is the FSM with a single stack.
▪ That is Pushdown Automata (PDA)
▪ When it reads ‘a’ it pushes ‘a’ onto a stack
and each time it sees ‘b’ it will pop ‘a’ from
stack. If it runs out of input and stack at
the same time and it is accepting, it will
accept it. Otherwise, it will reject.

▪ Design a PDA to accept palindrome string.


❖ The Decidable and Semidecidable Languages
▪ Some languages are not context-free.
▪ For Example: AnBnCn = {anbncn : n≥ 0}
▪ Using a PDA is not possible. We need a model which is stronger than
PDA.
▪ Instead of use of stack, use infinite tape. This tape will have a single
read/write head.

▪ The read/write head can be moved in one position in either direction on


each move. This machine is called the Turing Machine.
▪ At each step, a Turing machine M considers its current state and the
character that is on the tape directly under its read/Write head.
▪ Based on those 2 things, it chooses its next state, chooses a character to
write on the tape, and decides whether the head is to be moved towards
left or right.
▪ The tape is infinite, and TM moves left as well as a right. Hence TM
does not guaranted to halt.
▪ Unfortunately, we can prove that there exists no algorithm that can
examine a TM and tells whether it will halt or not. This leads to the
undecidability of the halting problem.
▪ We define TM to define 2 next classes of language
▪ A language L is decidable iff there exists a Turing machine M that
halts on all inputs, accepts all strings that are in L, and rejects all
strings that are not in L. In other words, M can always say yes or no, as
appropriate. •
▪ A language L is semidecidable iff there exists a Turing machine M
that halts on all inputs, accepts all strings that are in L, and fails to
accept every string that is not in L. Given a string that is not in L, M
may reject or it may loop forever. In other words, M can recognize a
solution and then say yes, but it may not know when it should give up
looking for a solution and say no.
▪ Example: Bal, AnBn, PalEven, WW, and AnBnCn are all decidable
languages.
▪ Every decidable language is also. But some languages are
semidecidable yet not decidable.
▪ As an example, consider L = {<p,w>: p is a Java program that halts on
input w}.
▪ (without having to run it)
▪ So it has no way to halt and reject.
▪ Just as there exists no algorithm that can examine a Turing machine
and decide whether or not it will halt, there is no algorithm to examine
a Java program (without having to run it) and make that
determination. So L is semidecidable but not decidable.
▪ Tools can be selected based on
❖ Computational efficiency:
Finite state machines run in time that is linear in the length of the
input string.
A general context-free parser based on the idea of a pushdown
automaton requires time that grows as the cube of the length of the
input string.
A Turing machine may require time that grows exponentially with the
length of the input string.
❖ Decidability:
There exist procedures to answer many useful questions about finite
state machines.
For example, does an FSM accept some particular string? Is an FSM
minimal (i.e., is it the simplest machine that does the job it does)? Are
two FSMs identical? A subset of those questions can be answered for
pushdown automata.
None of them can be answered for Turing machines.
❖ Clarity:
There are tools to design FSM and every regular language can also be
described using Regular Expression.
Every CFL recognized y some PDA cab be described by CF grammar.
No corresponding tool exists for the boarded classes of decidable and
semidecidable languages.
REGULAR EXPRESSIONS

The language accepted by DFA or NFA and ε-NFA is


called regular language.
A regular language can be described using regular
expressions consisting of the symbols such as alphabet
in Σ, the operators such as ‘.’,’+’ and ‘*’.
The three operators used to obtain a regular expression are:
+ :union operator
.: concatenation operator
*: closure operator
Regular expression
Definition: A regular expression is recursively
defined as follows.
1.ϕ is a regular expression denoting an empty language.
2. ε-(epsilon) is a regular expression indicates the language
containing an empty string.
3. a is a regular expression which indicates the language
containing only {a}
4. If R is a regular expression denoting the language LR and
S is a regular expression denoting the language LS, then
a. R+S is a regular expression corresponding to the
language LRULS.
b. R.S is a regular expression corresponding to the
language LR.LS..
c. R* is a regular expression corresponding to the
language LR*.
5. The expressions obtained by applying any of the rules
from 1-4 are regular expressions.
The table shows some examples of regular expressions and
the language corresponding to these regular expressions.
INTRODUCTION TO
FINITE AUTOMATA
? Symbols used in FA

Symbols Meaning
A circle is used to represent a state. Here, q0 is
q0 a state of the machine.

q0 A circle with an arrow which is not originating


from any node represent start state of
machine.
q0 Two circle are used to represent a final state.
Here, q0 is a final state of the machine.
1
q0 q1 An Arrow with label 1 goes from state q0 to q1.
Indicates there is a transition from state q0 to
q1 on input symbol 1. Represented as δ(q0,1)=q1
INTRODUCTION TO
FINITE AUTOMATA
? Symbols used in FA

Symbols Meaning
An Arrow with label 0 starts and ends in q0.
Indicates the machine in state q0 on reading a
q0 0 0, it remains in same state q0 .Represented as δ
(q0,0)=q0

An Arrow with label 0,1 goes from state q0 to q1.


0,1 Indicates the machine in state q0 on reading a 0
q0 q1
or 1 enters into state q1. Represented as δ
(q0,0)=q1 δ(q0,1)=q1
DETERMINISTIC FINITE
AUTOMATA(DFA)
• A deterministic finite automaton (DFA) is a 5-tuple or quintuple
indicating five components:
M= (Q, Σ, δ, q0, F)
where
⚫ Q is a finite set of states
⚫ Σ is an alphabet(finite set of input symbols)
⚫ δ: Q × Σ → Q is a transition function which is a mapping from
Q × Σ to Q.
⚫ q0 ϵ Q is the initial state
⚫ F ⊆ Q is a set of final states (or accepting states ).
⚫ M is the name of the machine.
• The term “deterministic” refers to the fact that on each input there
is one and only one state to which the automaton can transition
from the current state. Since it has a finite number of states the
machine is called Deterministic finite automata(DFA)
? A Finite Automata can be represented by a
a) Transition diagram
b) Transition table
? Transition diagram:
? A transition graph contains
a. Set of states as circles, start state q0 with arrow,
final state by double circle.
b. A finite set of transition that show how to go from
some state to other.
? Transition table
? It is a tabular representation where rows
correspond to states and column correspond to
input. Start State is given by and final state by
*
DETERMINISTIC FINITE
AUTOMATA(DFA)
How a DFA processes strings
First thing to understand about a DFA is how the
DFA decides whether or not to “accept” a sequence of
input symbols.
The “language” of the DFA is the set of all strings that
the DFA accepts.
Example : lets specify a DFA that accepts all and only
the strings of 0’s and 1’s that have the sequence 01
somewhere in the string.
L: { x01y | x and y are any strings of 0’s and 1’s}
DETERMINISTIC FINITE
AUTOMATA(DFA)
00110
0 0 1 1 0

δ(q0,0)=q0
δ(q0,0)=q0

δ(q0,1)=q1

δ(q1,1)=q2

δ(q2,0)=q2
EXTENDED TRANSITION
FUNCTION OF DFA TO STRINGS:
Definition
The Extended Transition function δ* describes
what happens to a state of machine when input is
a string (sequence of symbols).
Let M= (Q, Σ, δ, q0, F) be a FA. The extended
transition function δ*: Q X Σ* to Q is defined
recursively as shown below:
Basis: δ* (q,ε) = q
Induction : let w=xa
δ* (q, w) = δ* (q, xa) =δ(δ* (q, x),a)=p
Extended Transition function of DFA to strings:
The various properties of Extended Transition
function are:
δ* (q,ε) = q
δ* (q, w) = δ* (q, xa) =δ(δ* (q, x),a) where w=xa
δ* (q, w) = δ* (q, ax) = δ*(δ (q, a),x) where w=ax

For Ex:
δ* (q, w) =q
PROBLEMS ON DFA
Define a DFA to accept ( Σ = {a})
1. Empty language L={ Φ}
2. Empty string L= {ε}
3. Exactly one a
4. Zero or more a’s
5. At least one a
6. At most one a
Empty language L={ Φ}
Empty string L= {ε}
Exactly one a
Zero or more a’s
1. At least one a
2. At most one a
DRAW A DFA TO ACCEPT STRINGS OF A’S AND B’S

1. Having at least one a.


14. Starting with atleast two a’s
2. Having exactly one a and Ending with atleast two b’s
3. Starting with the string ab 15. Not having more than three a’s
4. Ending with the string abb 16. Either begins or ends or both
5. Do not end with the string abb with the substring 01
6. Having substring aab 17. L={w: na(w) ≥ 1, nb(w) = 2 }
7. Except those having the 18. L = {w Є {a, b}* : every ‘a’ is
substring aab immediately followed by ‘b’}
8. Having three consecutive a’s 19. No More Than One b.
9. Not having more than three a’s 20. No Two Consecutive Characters
10. L={awa|w Є (a+b)n where n≥ 0} Are the Same.
11. Ending with ab or ba 21. Floating Point Numbers.
12. Having four a’s 22. A Simple Communication
13. At most two consecutive b’s Protocol
Divide by K Problem.
Construct a DFA which accepts strings of 0’s and 1’s where the
23.

value of each string is represented as a binary number. Only the


strings representing zero modulo five should be accepted. For
example, 0000,0101, 1010, 1111 etc should be accepted.
Obtain a DFA which accepts the set of all strings beginning with a
24.

1 that when interpreted as a binary integer, is a multiple of 5. For


example, 101, 1010, 1111 etc are multiples of 5. Note that 0101 is
not beginning with 1 and it should not be accepted.
Draw a DFA to accept decimal strings divisible by 3.
25.

L={w: |w| mod 3=0} on ∑={a,b}


26.

Modulo K counter problem:


Draw a DFA to accept strings of a’s and b’s.
27.

Having even number of a’s and even number of b’s.


28.

Having even number of a’s and odd number of b’s.


29.

Having odd number of a’s and even number of b’s.


30.

Having odd number of a’s and odd number of b’s.


31.
HAVING AT LEAST ONE A.
HAVING EXACTLY ONE A

Trap State: A state for which there


exists transitions to itself for all the
input symbols chosen from ∑
STARTING WITH THE STRING AB
ENDING WITH THE STRING ABB
DO NOT END WITH THE STRING
ABB
HAVING SUBSTRING AAB

EXCEPT THOSE HAVING THE


SUBSTRING AAB
L={awa |w Є (a+b)n where n≥ 0}
FLOATING POINT NUMBERS
❑ Assume the following syntax for floating point numbers:
✔ A floating-point number is an optional sign, followed by a decimal number,
followed by an optional exponent.
✔ A decimal number may be of the form x or x.y, where x and y are nonempty
strings of decimal digits.
✔ An exponent begins with E, followed by an optional sign and then an integer.
✔ An integer is a nonempty string of decimal digits.
✔ So, for example, these strings represent floating point numbers:
+3.0, 3.0, 0.3E1, 0.3E+1, -0.3E+1, -3E8,3
Regular language
Definition: Let M = (Q, Σ, δ, q0, A) be a DFA. The
language L is regular if there exists a machine M
such that L = L(M).
APPLICATIONS OF FINITE
AUTOMATA
Design of digital circuit
Compiler construction
String matching
String processing
Software design
Other applications
DISADVANTAGES OF DFA
Constructing a DFA is difficult.
The DFA can not guess about its input.
The DFA is not very powerful.
At any point of time, the DFA is in only one
state.
WHY NFA
All disadvantages of DFA can be overcome using
Non-deterministic Finite Automata(NFA).
Advantages of NFA
Very easy to construct.
A “Non-deterministic” FA has the ability to guess
something about input.
A NFA is more powerful than DFA.
It has the power to be in several states at once.
An NFA is an efficient mechanism to describe some
complicated languages concisely.
NON-DETERMINISTIC FINITE
AUTOMATA(NFA)
A Non-deterministic finite automaton (NFA) is a 5-tuple or
quintuple indicating five components:
M= (Q, Σ, δ, q0, F)
where
⚫ Q is a finite set of states
⚫ Σ is an alphabet(finite set of input symbols, non-empty)
⚫ δ : Q × Σ → 2Q is a transition function which is a
mapping from Q × Σ to 2Q
⚫ q0 ϵ Q is the initial state
⚫ F ⊆ Q is a set of final states (or accepting states ).
⚫M is the name of the machine.
• Draw a NFA to accept the strings of a’s and b’s of the language
• Starting with ab
• Ending with ab
• Ending with ab or ba
• L-={w| w Є ababn or aban where n ≥ 0 }
• Set of strings abc, abd and aacd.

▪ Starting with ab
▪ Ending with ab

▪ Ending with ab or ba
• L-={w| w Є ababn or aban where n ≥ 0 }

• Set of strings abc, abd and aacd.


CONVERSION FROM NFA TO DFA

▪ NFA can be converted into DFA using two methods.

▪ Subset Construction method


▪ Lazy evaluation method.
SUBSET CONSTRUCTION METHOD
▪ Step 1: Identify the start state of DFA: since q0 is the start
state of NFA, {q0} is the start state of DFA
▪ Step 2 : Identify the alphabets of DFA: the input alphabets of
DFA are the input alphabets of NFA.
▪ Step 3: Identify the states of DFA(QD) : The set of subsets of QN
will be the states of DFA QD . So, if QN has n states then QD will
have 2n states.
Example : Let QN ={q0, q1, q2,} then | QN | =3
QD ={{ }, {q0}, {q1}, {q2}, {q0, q1}, {q0, q2}, {q1, q2}, {q0, q1, q2}}
So, |QD |=8
▪ Step 4: Identify the final states of DFA: final states of NFA is
the final state of DFA.
▪ Step 5: Identify the transitions of DFA: obtain transition for
each state of DFA and for each input symbol.
OBTAIN A DFA FOR THE FOLLOWING NFA
USING SUBSET CONSTRUCTION METHOD
▪ Solution:
▪ Step 1: Identify the start state of DFA: since q0 is the start state of
NFA, {q0} is the start state of DFA.
▪ Step 2 : Identify the alphabets of DFA: ∑={a,b}
▪ Step 3: Identify the states of DFA(QD) : Here, QN ={q0, q1, q2,}. Its
subsets are the states of DFA QD . So, states of DFA are
Example : QD ={{ }, {q0}, {q1}, {q2}, {q0, q1}, {q0, q2}, {q1, q2}, {q0, q1, q2}}
So, |Q D |=8
▪ Step 4: Identify the final states of DFA:
FD ={{q2}, {q0, q2}, {q1, q2}, {q0, q1, q2}}
▪ Step 5: Identify the transitions of DFA: obtain transition for each state
of DFA and for each input symbol.
Step 5: Identify the transitions of DFA: obtain transition

for each state of DFA and for each input symbol.


DISADVANTAGES OF SUBSET
CONSTRUCTION METHOD
▪ In the Subset construction method, there are 2n states, and from
each state, we have the transition from the input symbol ∑ hence
the time complexity to convert an NFA to DFA is ∑* 2n.
▪ The procedure takes a very long time to construct the table.
▪ The exponential time complexity can be avoided using another
technique called the lazy evaluation method.
LAZY EVALUATION METHOD
▪ Step 1: Identify the start state of DFA: since q0 is the start state of
NFA, {q0} is the start state of DFA
▪ Step 2: Identify the alphabets of DFA: the input alphabets of DFA are
the input alphabets of NFA.
▪ Step 3: Identify the transitions of DFA(QD) : For each state{qi, qj,.......,qk}
in QD and for each input symbol an in ∑, the transition can be obtained
as shown below :
δD({qi, qj,…….,qk},a) = δN(qi , a) U δN(qj , a) U…. δN(qk , a)
= [q1, qm ,……qn] say
• Add the state [q1, qm,……qn] to QD, if it is not already in QD.
• Add the transitions from [qi, qj,…….,qk] to [q1, qm ,……qn] on the input
symbol a.
• Note: step 3 has to be repeated for each state that is added to QD
▪ Step 4: Identify the final states of DFA: if {qi, qj,…….,qk} is a state in QD
and if one of qi, qj,…….,qk is the final state of NFA, then {qi, qj,…….,qk} will
be the final state of DFA.
OBTAIN A DFA FOR THE FOLLOWING
NFA USING LAZY EVALUATION
METHOD
▪ Solution:
▪ Step 1: Identify the start state of DFA: since q0 is the start
state of NFA, {q0} is the start state of DFA.
▪ Step 2: Identify the alphabets of DFA: ∑={a,b}
▪ Step 3: Identify the transitions of DFA(QD) : start from the
start state q0 and find the transitions

▪ Step 4: Identify the final states of DFA: F={q0, q2}


OBTAIN A DFA FOR THE FOLLOWING
NFA USING LAZY EVALUATION
METHOD
▪ Solution:
▪ Step 1: Identify the start state of DFA: since q0 is the start
state of NFA, {q0} is the start state of DFA.
▪ Step 2: Identify the alphabets of DFA: ∑={a, b}
▪ Step 3: Identify the transitions of DFA(QD) : start from the
start state q0 and find the transitions

▪ Step 4: Identify the final states of DFA:


▪ F={{q2},{q1 ,q2}, {q0 ,q1 ,q2}}
▪ obtain an NFA to accept strings of ’s and b’s ending
with ab or ba. From this obtain an equivalent DFA

Solution:

Step 1: Identify the start state of DFA: since q0 is the start state of

NFA, {q0} is the start state of DFA.


Step 2: Identify the alphabets of DFA: ∑={a, b}

▪ Step 3: Identify the transitions of DFA(QD) : start from
the start state q0 and find the transitions

▪ Step 4: Identify the final states of DFA:


▪ F={{q0 q2 q3},{q0 q1 q4}}
ε- NFA (NON-DETERMINISTIC FINITE
AUTOMATON WITH EPSILON TRANSITIONS)
Definition :a transition with an empty input
string is called an ε- transition. That is, if there is a
transition from one state to another state without any
input.
ε- NON-DETERMINISTIC FINITE
AUTOMATA(ε- NFA)
A ε- Non-deterministic finite automaton (NFA) is a 5-tuple
or quintuple indicating five components:
M= (Q, Σ, δ, q0, F)
where
⚫ Q is a finite set of states
⚫ Σ is an alphabet(finite set of input symbols, non-empty)
⚫ δ : Q × (Σ U ε)→ 2Q is a transition function which is a
mapping from Q × (Σ U ε) to 2Q
⚫ q0 ϵ Q is the initial state
⚫ F ⊆ Q is a set of final states (or accepting states ).
⚫ M is the name of the machine.
Note: in an ε-NFA, there can be zero, one, or more transitions with or without any
input symbols.
ε- NFA
▪ Obtain an ε- NFA which accepts strings consisting of zero
or more a’s followed by zero or more b’s followed by zero or
more c’s.
CONVERSION FROM ε- NFA to DFA
ε- Closure
Definition: The ε- Closure of q denoted by ECLOSE(q) is
the set of all states which are reachable from q on ε-transitions
only.
⚫ state q is in ECLOSE(q), i.e., ECLOSE(q)=q.
⚫ If ECLOSE(q) contains p and if there is a transition from state p to r
labelled ε, then state r is also in ECLOSE(q).

For the above diagram


⚫ ECLOSE(q0)={q0,q1,q2}
⚫ ECLOSE(q1)={q1,q2}
⚫ ECLOSE(q2)={q2}
CONVERT THE FOLLOWING NFA TO
ITS EQUIVALENT DFA

ECLOSE(q0) ={q0, q1, q2}


ECLOSE(q1) ={ q1, q2}
ECLOSE(q2) ={ q2}
Solution:
Step 1: if q0 is the start state of NFA, then ECLOSE(q0) is the start
state of DFA.
ECLOSE(q0) ={q0, q1, q2}
▪ Step 2: Compute the transitions for DFA
▪ Step 3: Identify the final state. F={{q0, q1, q2}, {q1, q2}, {q2}}
CONVERT THE FOLLOWING NFA TO
ITS EQUIVALENT DFA
ECLOSE(0) = {0}
ECLOSE(1) = {1}
ECLOSE(2) = {2, 3, 4, 6, 9}
ECLOSE(3) = { 3,4,6}
ECLOSE(4) = {4}
ECLOSE(5) = {5, 8, 3, 4, 6, 9}= {3, 4, 5, 6, 8, 9}
ECLOSE(6) = {6}
ECLOSE(7) = {7, 8, 3, 4,6, 9}= {3, 4, 6, 7, 8, 9}
ECLOSE(8) = {8, 3, 4, 6, 9}= {3, 4, 6, 8, 9}
ECLOSE(9) = {9}

δ a b
->{0} {1} Φ
{1} Φ {2, 3, 4, 6, 9}
*{2, 3, 4, 6, 9} {3, 4, 5, 6, 8, 9} {3, 4, 6, 7,8, 9}
*{3, 4, 5, 6, 8, 9} {3, 4, 5, 6, 8, 9} {3, 4, 6, 7, 8, 9}
*{3, 4, 6, 7, 8, 9} {3, 4, 5, 6, 8, 9} {3, 4, 6, 7, 8, 9}
MINIMIZING FSMS

▪ Equivalence of Two States


▪ The language generated by a DFA is unique.
▪ But, many DFA’s can accept the same language. In such
cases, the DFA’s are said to be equivalent.
▪ During computations, it is desirable to represent the
DFA with fewer states since the space is proportional
to the number of states of the DFA.
▪ For storage efficiency, the number of states must be
reduced; hence, the DFA must be minimized. This can
be achieved first by finding the distinguishable and
indistinguishable states.
▪ First, let us see “What are distinguishable and
indistinguishable states?”.
▪ Definition:
▪ Two states p and q of a DFA are equivalent
(indistinguishable) if and only if δ(p, w) and δ(q, w) are final
states or both δ(p, w) and δ(q, w) are non-final states for all w ∈
Σ* i.e. if
δ(p, w) ∈ F and δ(q, w) ∈ F
▪ then the states p and q are indistinguishable. If
δ(p, w) ∉ F and δ(q, w) ∉ F
▪ then also the states p and q are indistinguishable. If there is at
least one string w such that one of
δ(p, w) and δ(q, w)
▪ is final state and the other is non-final state, then the
states p and q are not equivalent and are
called distinguishable states.
MINIMIZE THE GIVEN DFA
Initially, classes = {[2, 4], [1, 3, 5, 6]}.
Step 1:
((2, a), [1, 3, 5, 6]) ((4, a), [1, 3, 5, 6])
((2, b), [1, 3, 5, 6]) ((4, b), [1, 3, 5, 6])
No splitting is required here.

((1, a), [2, 4]) ((3, a), [2, 4]) ((5, a), [2, 4]) ((6, a), [1, 3, 5, 6])
((1, b), [2, 4]) ((3, b), [2, 4]) ((5, b), [2, 4]) ((6, b), [1, 3, 5, 6])

There are two different patterns, so we must split into two


classes, [1, 3, 5] and [6]. Note that, although [6] has the same
behavior as [2, 4] after reading a single character, it cannot be
combined with [2, 4] because they do not share behavior after
reading no characters.

Classes = {[2, 4], [1, 3, 5], [6]}.


Step 2:
((2, a), [1, 3, 5]) ((4, a), [6]) These two must be split.
((2, b), [6]) ((4, b), [1, 3, 5])

((1, a), [2, 4]) ((3, a), [2, 4]) ((5, a), [2, 4])
((1, b), [2, 4]) ((3, b), [2, 4]) ((5, b), [2, 4]) No splitting is required here

Classes = {[2], [4], [1, 3, 5], [6]}.

Step 3:
((1, a), [2]) ((3, a), [2]) ((5, a), [2])
((1, b), [4]) ((3, b), [4]) ((5, b), [4]) No splitting required here.
MINIMIZE THE GIVEN DFA
MINIMIZE THE GIVEN DFA
SIMULATORS FOR FSMS
▪ Once we have created an FSM to solve a problem, we may
want to simulate its execution.
▪ Simulating Deterministic FSMs
▪ We begin by considering only deterministic FSMs. One
approach is to think of an FSM as the specification for a
simple, table-driven program and then proceed to write the
code.
• Given an FSM M with states K, this approach will
create a program of length = 2 + (|K|.(|∑| + 2)).
• The time required to analyze an input string w is
O(|w| . |∑|).
• The biggest problem with this approach is that we
must generate new code for every FSM that we wish
to run.
SIMULATING NONDETERMINISTIC
FSMS
? Difference between DFA, NFA and ε-NFA
DFA NFA ε-NFA
The DFA is a 5-tuple The NFA is a 5-tuple The ε-NFA is a 5-tuple
M= (Q, Σ, δ, q0, F) M= (Q, Σ, δ, q0, F) M= (Q, Σ, δ, q0, F)
Where Where Where
Q is set of finite states.
• Q is set of finite states.
• Q is set of finite states.

Σ is set of input alphabets


• Σ is set of input alphabets
• Σ is set of input alphabets

δ :Q x Σ to Q
• δ :Q x Σ to 2Q
• δ :Q x (Σᴜε ) to 2Q

q0 is the start state.


• q0 is the start state.
• q0 is the start state.

F⊆Q is set of final states


• F⊆Q is set of final states
• F⊆Q is set of final states

There can be zero or one There can be zero, one or There can be zero, one or
transition from a state on more transition from a state more transition from a state
an input symbol. on an input symbol. with or without giving input
.
More number of transitions. Less number of transitions. Relatively more transitions
when compared with NFA

Difficult to construct Easy to construct Easy to construct using


regular expression.
Less powerful since at any More powerful than DFA More powerful than NFA .at
point of time it will be in since at any point of time it any point of time it will be
only one state. will be in more than in more than one state with
onestate or without giving any input.
Difference between DFA, NFA and ε-NFA
DFA NFA ε-NFA
The DFA is a 5-tuple The NFA is a 5-tuple The ε-NFA is a 5-tuple
M= (Q, Σ, δ, q0, F) M= (Q, Σ, δ, q0, F) M= (Q, Σ, δ, q0, F)
Where Where Where
Q is set of finite states.
• Q is set of finite states.
• Q is set of finite states.

Σ is set of input alphabets


• Σ is set of input alphabets
• Σ is set of input alphabets

δ :Q x Σ to Q
• δ :Q x Σ to 2Q
• δ :Q x (Σᴜε ) to 2Q

q0 is the start state.


• q0 is the start state.
• q0 is the start state.

F⊆Q is set of final states


• F⊆Q is set of final states
• F⊆Q is set of final states

There can be zero or one There can be zero, one or There can be zero, one or
transition from a state on an more transition from a state more transition from a state
input symbol. on an input symbol. with or without giving input

More number of transitions. Less number of transitions. Relatively more transitions


when compared with NFA
Difficult to construct Easy to construct Easy to construct using
regular expression.
Less powerful since at any More powerful than DFA More powerful than NFA .at
point of time it will be in since at any point of time it any point of time it will be in
only one state. will be in more than more than one state with or
onestate without giving any input.

You might also like