Unit-1 ATCD
Unit-1 ATCD
Introduction
Syllabus
String
Alphabet
Language
Operations
equivalence of DFA ‘s
Introduction
• Automata: it is a mathematical model or
abstract model.
• It is helpful for check whether the given string
belongs to language or not.
• Finite automata : it is a model (or) machine
which runs in a finite state is called finite
automata.
Representation & Notations used in
Automata
Symbols: Symbols are an entity or individual objects, which can be any letter, alphabet or
any picture.
• Example: 1, a, b, #
Alphabets: Alphabets are a finite set of symbols. It is denoted by ∑.
• Examples: ∑ = {a, b} , ∑ = {A, B, C, D} , ∑ = {0, 1, 2} , ∑ = {0, 1, ....., 5] ,
∑ = {#, β, Δ}
String: it is a collection of symbols over alphabet. The string is denoted by w.
Example 1:
• If ∑ = {a, b}, various string that can be generated from ∑ are {ab, aa, aaa, bb, bbb, ba,
aba.....}.
• A string with zero occurrences of symbols is known as an empty string. It is
represented by ε.
• The number of symbols in a string w is called the length of a string. It is denoted by |w|.
Example 2: w = 010
• Number of Sting |w| = 3
Language
• It is a collection or set of all strings over alphabet.
• It is represented as ‘L’
• A language which is formed over Σ can be Finite or Infinite.
• Given an alphabet I, a language L is a set of strings, that is a subset of
the universal language I.
Example: 1
• L1 = {Set of string of length 2} = {aa, bb, ba, bb} Finite Language
Example: 2
• L2 = {Set of all strings starts with 'a'} = {a, aa, aaa, abb, abbb,
ababb…} Infinite Language
Operations
• On languages we can define the usual set operations that are.
union
intersection
Complement
∑-ε=∑
Finite Automata
• Finite automata are used to recognize patterns.
• It takes the string of symbol as input and changes its state accordingly. When the
desired symbol is found, then the transition occurs.
• At the time of transition, the automata can either move to the next state or stay in the
same state.
• Finite automata have two states, Accept state or Reject state. When the input string
is processed successfully, and the automata reached its final state, then it will accept.
Formal Definition of FA
• A finite automaton is a collection of 5-tuple (Q, ∑, δ, q0, F), where:
• Q: finite set of states
• ∑: finite set of the input symbol
• q0: initial state
• F: final state
• δ: Transition function
Transition Diagram:- Transition Table:-
A transition diagram or state transition The transition table is basically a tabular
diagram is a directed graph which can representation of the transition function. It
be constructed as follows: takes two arguments (a state and a symbol)
• There is a node for each state in Q, and returns a state (the "next state").
which is represented by the circle. A transition table is represented by the
• There is a directed edge from node following things:
q0 to node q1 labeled a if δ(q0, a) = q1. • Columns correspond to input symbols.
• In the start state, there is an arrow • Rows correspond to states.
with no source. • Entries correspond to the next state.
• Accepting states or final states are • The start state is denoted by an arrow
indicating by a double circle. with no source.
• The accept state is denoted by a star.
Example
0 Symbol
Stat
es
0 1
0
1 q0 q0 q1
q0 q1
1 *q1 q1 q0
Finite automata
• Finite automata are abstract machines used to recognize patterns in input sequences, forming the
basis for understanding regular languages in computer science.
They consist of states, transitions, and input symbols, processing each symbol step-by-step.
If the machine ends in an accepting state after processing the input, it is accepted; otherwise, it is
rejected.
Automata can be construct with help of
• States: it represent as circle with state name.
• Transitions: directed edge between two states.
• Initial state: state with an edge from no source.
• Final state: represented as double circle with state name.
Features of Finite Automata
• Input: Set of symbols or characters provided to the machine.
• Output: Accept or reject based on the input pattern.
• States of Automata: The conditions or configurations of the machine.
• State Relation: The transitions between states.
• Output Relation: Based on the final state, the output decision is made.
Finite Automata Model
• Finite automata can be represented by input tape and finite control.
• Input tape: It is a linear tape having some number of cells. Each input symbol is
placed in each cell.
• Finite control: The finite control decides the next state on receiving particular
input from input tape. The tape reader reads the cells one by one from left to right,
and at a time only one input symbol is read.
Acceptance of String& Language :
• A String is said to be accepted by a FA M=(Q,∑,δ,q0,F) if δ(q0,x)=p for some p in F.
⚫ A language is accepted if all the strings generated from the language is accepted.
⚫ A language is said to be regular if it is the set accepted by a FA M(Finite Automata Machine).
•Ex: δ(q0,111)= δ(δ(δ(q0,1),11)
• = δ(δ(q0,1),1)
• = δ(q1,1)
• = q2 ϵ F String is accepted.
• Acceptance of Strings:
• Scan the entire String, if the input string reaches to the final state from initial state in a given
Finite Automata(either DFA or NFA) then it is said to be string is accepted.
• Acceptance of language:
• A language is said to be accepted, if all the strings in the language are accepted and some
strings not in the language are rejected in Finite Automata(FA).
Chomsky hierarchy of languages
According to Noam Chomsky, there are four types of grammars −
Type 0, Type 1, Type 2, and Type 3. The following table shows how
they differ from each other −
Grammar Type Grammar Language Automaton
Accepted Accepted
State \ Symbol
a b
q0 q1 q0
q1 q1 q0
If the string ends in ‘a’, the machine reaches state q1, which is an accepting state.
Non Deterministic Finite Automata
In NDFA, for a particular input symbol, the machine can move to any
combination of the states in the machine. (The machine have multiple
paths on one input symbol)
In other words, the exact state to which the machine moves cannot be
determined. Hence, it is called Non-deterministic Automaton.
As it has finite number of states, the machine is called Non-deterministic
Finite Machine or Non-deterministic Finite Automaton.
Formal Definition of an NDFA:
An NDFA can be represented by a 5-tuple (Q, ∑, δ, q0, F) where
Q is a finite set of states.
∑ is a finite set of symbols called the alphabets.
δ is the transition function where δ: Q × ∑ → 2Q
(Here the power set of Q (2Q) has been taken because in case of NDFA,
from a state, transition can occur to any combination of Q states)
q0 is the initial state from where any input is processed (q0 ∈ Q).
F is a set of final state/states of Q (F ⊆ Q).
Non Deterministic Finite Automata
NFA is similar to DFA but includes the following features:
It can transition to multiple states for the same input.
It allows null (ϵ) moves, where the machine can change states without
consuming any input.
Example
Let a non-deterministic finite automaton be →
Construct an NFA that accepts strings ending in ‘a’.
Given:
Σ = {a, b}, Q = {q0, q1}, F = {q1}
The transition function δ as shown below by the transition diagram and
transition table −
State\
Symbol
a b
q0 {q0,q1} q0
q1 φ φ
Solution:
In the given solution, we can see that only input string 101 will
be accepted.
Hence, for input 101, there is no other path shown for other input.
• Example 3:
• Design FA with ∑ = {0, 1} accepts even number of 0's and even number
of 1's.
• Solution:
• This FA will consider four different stages for input 0 and input 1. The
stages could be:
DFA- Practice Problems
1) Design a FA that accepts set of strings such that every string ends in
00,over alphabet ∑={0,1}.
2) Construct a FA that accept set of strings where the number of 0’s in every
string is multiple of three over alphabet ∑={0,1}.
3) Design a FA which accepts set of strings containing exactly four 1’s in
every string over alphabet ∑={0,1}.
4) Design a FA that accept strings containing exactly one 1 over alphabet
∑={0,1}.
5) Give a DFA for Σ = {0, 1} and strings that have an odd number of 1’s
and any number of 0’s.
6) Give a DFA for Σ = {a, b, c} that accepts any string with "aab" as a
substring.
7) Give a DFA for Σ = {a, b} that accepts any string with
"aababb" as a substring.
DFA- Practice Problems
9. For the given FA write the language and also give the transition
table.
10. For the given FA write the language and also give the transition
table.
DFA- Practice Problems
11. Design a FA over alphabet ∑={0,1},which accept the set of
strings either start with 01 or end with 01.
12. Give the DFA accepting the set of strings over alphabet
∑={0,1},such that in each string number of 0’s is divisible by
five and number of 1’s is divisible by 3.
13. Construct DFA which accept a language ∑={a,b} of all strings
containing ‘a’
14. Construct DFA which accepts all the strings over an alphabet
∑={a,b} where length of a string =2.
NFA-Practice Problems
1. Design a NFA for the language L=all string over
{0,1} that have at least two consecutive 0’s or 1’s.
• Here,
• ε-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}
Conversion Of E-NFA To NFA
The Process Of Conversion Of ε-NFA To NFA Is Called As Thomson Construction.
Note:-
⚫ No Change In Initial State
⚫ No Change In The Total No. Of States
⚫ May Be Change In Final States
Algorithm
Let M=(Q,Σ,δ,q0,F) – ε-NFA
M1= (Q1,Σ,δ1,q01,F1) – NFA
1) Initial State
q01=q0
2) Construction Of δ1
δ1
(q,x)=ε-Closure(δ(ε-Closure(q),x)
3) Final State
Every State Who’s ε-Closure Contain Final State Of ε-NFA Is Final State In NFA
Conversion Of E-NFA To NFA -example
⚫ ε-Closure(q0)-{q0,q1}
⚫ ε-Closure(q1)-{q1}
1. Initial State : q0
2. Construction Of δ1
δ1=(q0,0)=ε-Closure(δ(ε-Closure(q0,0)
=ε-Closure(δ({q0,q1},0))
=ε-Closure(q0)
={q0,q1}
Conversion Of E-NFA To NFA -example
δ1=(q0,1)=ε-Closure(δ(ε-Closure(q0,1)
=ε-Closure(δ({q0,q1},1))
=ε-Closure(q1)
={q1}
δ1=(q1,0)=ε-Closure(δ(ε-Closure(q1,0)
=ε-Closure(δ({q1},0))
=ε-Closure(Φ)
=Φ
δ1=(q1,1)=ε-Closure(δ(ε-Closure(q1,1)
=ε-Closure(δ({q1},1))
=ε-Closure(q1)
={q1}
Conversion Of E-NFA To NFA -example
3. Final State?
⚫ q0 & q1 Both Are Final States Because
ε-Closure(q0)={q0,q1}
ε-Closure(q1)={q1}
Conversion from NFA to DFA
Let, M = (Q, ∑, δ, q0, F) is an NFA which accepts the
language L(M). There should be equivalent DFA denoted by
M' = (Q', ∑', q0', δ', F') such that L(M) = L(M').
Steps for converting NFA to DFA:
⚫ Step 1: Initially Q' = ϕ
⚫ Step 2: Add q0 of NFA to Q'. Then find the transitions
from this start state.
⚫ Step 3: In Q', find the possible set of states for each input
symbol. If this set of states is not in Q', then add it to Q'.
⚫ Step 4: In DFA, the final state will be all the states which
contain F(final states of NFA)
Conversion from NFA to DFA-
Example
State 0 1
→q0 q0 q1
q1 {q1, q2} q1
Minimization of FSM:
Minimization of FSM:
⚫ Step 1. P0 will have two sets of states. One set will contain q1, q2, q4 which
are final states of DFA and another set will contain remaining states. So P0 =
{
{ q1, q2, q4 }, { q0, q3, q5 } }.
Step 2. To calculate P1, we will check whether sets of partition P0 can
be partitioned or not:
⚫ For set { q1, q2, q4 } :
δ ( q1, 0 ) = δ ( q2, 0 ) = q2 and δ ( q1, 1 ) = δ ( q2, 1 ) = q5, So q1 and
q2 are
not distinguishable.
Similarly, δ ( q1, 0 ) = δ ( q4, 0 ) = q2 and δ ( q1, 1 ) = δ ( q4, 1 ) = q5, So
q1 and q4 are not distinguishable.
Since, q1 and q2 are not distinguishable and q1 and q4 are also
not distinguishable, So q2 and q4 are not distinguishable. So,
{ q1, q2, q4 } set will not be partitioned in P1.
Minimization of FSM:
⚫ For set { q0, q3, q5 } :
δ ( q0, 0 ) = q3 and δ ( q3, 0 ) =
q0 δ ( q0, 1) = q1 and δ ( q3, 1 )
= q4
Moves of q0 and q3 on input symbol 0 are q3 and q0 respectively which are
in same set in partition P0. Similarly, Moves of q0 and q3 on input symbol
1 are q3 and q0 which are in same set in partition P0. So, q0 and q3 are not
distinguishable.
⚫ δ ( q0, 0 ) = q3 and δ ( q5, 0 ) = q5 and δ ( q0, 1 ) = q1 and δ ( q5, 1 ) = q5
Moves of q0 and q5 on input symbol 0 are q3 and q5 respectively which
are in different set in partition P0. So, q0 and q5 are distinguishable. So,
set { q0, q3, q5 } will be partitioned into { q0, q3 } and { q5 }. So,
P1 = { { q1, q2, q4 }, { q0, q3}, { q5 } }
Minimization of FSM:
⚫ To calculate P2, we will check whether sets of partition P1 can be partitioned
or not:
⚫
For set { q1, q2, q4 } :
δ ( q1, 0 ) = δ ( q2, 0 ) = q2 and δ ( q1, 1 ) = δ ( q2, 1 ) = q5, So q1 and q2
are not distinguishable.
Similarly, δ ( q1, 0 ) = δ ( q4, 0 ) = q2 and δ ( q1, 1 ) = δ ( q4, 1 ) = q5, So
q1 and q4 are not distinguishable.
Since, q1 and q2 are not distinguishable and q1 and q4 are also not
distinguishable, So q2 and q4 are not distinguishable. So,
{ q1, q2, q4 } set will not be partitioned in P2.
Minimization of FSM:
⚫ For set { q0, q3 } :
δ ( q0, 0 ) = q3 and δ ( q3, 0 ) =
q0 δ ( q0, 1 ) = q1 and δ ( q3, 1 )
= q4
Moves of q0 and q3 on input symbol 0 are q3 and q0 respectively which are
in same set in partition P1. Similarly, Moves of q0 and q3 on input symbol 1
are q3 and q0 which are in same set in partition P1. So, q0 and q3 are not
distinguishable.
⚫ For set { q5 }:
Since we have only one state in this set, it can’t be further partitioned. So,
P2 = { { q1, q2, q4 }, { q0, q3 }, { q5 } }
Since, P1=P2. So, this is the final partition. Partition P2 means that q1, q2
and q4 states are merged into one. Similarly, q0 and q3 are merged into one.
Minimized DFA corresponding to DFA of Figure 1 is shown in Figure 2 as:
Minimization of FSM:
Equivalence between two FSM’s:
States/Inputs c d