Flat Unit 1r19
Flat Unit 1r19
INDEX
3 Automation 6
4 Finite Automation 6
KHIT,CSE Page 1
www.Jntufastupdates.com
Formal Languages and Automata Theory – R16
There are several reasons why the study of automata and complexity is an important part of
the core of Computer Science.
Computer science can be divided into two main branches.
1. “Applied Computer Science” which is concerned with the design and implementation of
computer systems, with a special focus on software.
2. “Theoretical Computer Science” or “Theory of computation” which is concerned with
mathematical study of computation.
The theories of computability and complexity are closely related. In complexity theory, the
objective is to classify problems as easy ones and hard ones; whereas in computability theory,
the classification of problems is by those that are solvable and those that are not .
Computational Problem:
Computation:
“Computation” can be defined as finding a solution to a problem from the given inputs by
means of an algorithm.
Automata theory:
It deals with the formal definitions and properties of mathematical models of computation.
These models play a role in several applied areas of computer science. One model, called the
finite automaton, is used in text processing, compilers, and hardware design. Another model,
called the context-free grammar, is used in programming languages and artificial intelligence.
KHIT,CSE Page 2
www.Jntufastupdates.com
Formal Languages and Automata Theory – R16
Proper prefix: prefix of a string other than itself is called proper prefix.
Example: w=sri, proper prefix=sr,s, ɛ.
suffix of a string: prefix of a string is formed by removing zero or more leading symbols of
the string. For a string of length n, number of suffixes= n+1.
Example: w=sri, suffix=sri,ri,i,ɛ.
Proper suffix: prefix of a string other than itself is called proper prefix.
Example: w=sri, proper suffix= ri,i,ɛ.
substring of a string: substring of a string is formed by removing either prefix or suffix or
both from a string excluding ɛ. For a string of length n, number of substrings= n(n+1)/2.
Example: w=sri, substring=sri, sr,s,ri,i,r
Language: language is a collection of strings formed from a particular alphabet.
Example: if ∑= {0, 1}, then the language of all strings consisting of n 0' s followed by n l' s,
for some n≥0 is L= {ɛ, 01,0011,000111,. .}.
Operations on strings:
1. Concatenation of a string
2. Kleene closure of a string
KHIT,CSE Page 3
www.Jntufastupdates.com
Formal Languages and Automata Theory – R16
Operations on languages:
1. Union of a language
2. Intersection of a language
3. Difference of a language
4. Complement of a language
5. Concatenation of a language
6. Kleene closure of a language
7. Positive closure of a language
Union of a language: Union of two languages is defined as collection of strings from L1 as
well as from L2. It is denoted as L1∪L2.
L1∪L2={w| w in L1 or w in L2}
KHIT,CSE Page 4
www.Jntufastupdates.com
Formal Languages and Automata Theory – R16
LC =∑* −L
Example: if L= {set of strings that starts with 010} over ∑= {0, 1}
then LC =∑* −L ={set of all strings} −{set of strings that starts with 010}
= { of strings that does not starts with 010}
Concatenation of a language: Concatenation of a two languages is obtained by appending
every string in second language at the end of every string in first language. If L1 and L2 are
two languages, then L1.L2 or L1L2 denotes the concatenation of L1 and L2.
L+ = L1 ∪L2 ∪ L3 ∪… or L+ = L*-{ɛ}
Example: if ∑= {0, 1}, }, then language containing strings of length 1 is L= {0, 1},
then L0 = {ɛ}
L1= L0.L ={ɛ} {0,1}={0,1}
L2= L1.L = {0,1}{0,1}={00,01,10,11}
KHIT,CSE Page 5
www.Jntufastupdates.com
Formal Languages and Automata Theory – R16
Automata:
Automata is plural for the term “Automaton”. An Automaton is defined as a system where
information is transmitted and used for performing some internal operations without direct
participation of human.
Definition:
“Finite State Machine” is a model of computation which is used to simulate the behaviour of
a machine or a system.
Input tape:
It is used to store the input string that is to be processed by Finite State Machine. The input is
finite and taken from a set of input alphabets ∑.
Read head:
It is used to read one symbol at a time from input tape and moves from left to right. Initially it
points to the leftmost symbol on the tape and it is controlled by “Finite control”.
Finite Control:
Finite control contains a set of states which are connected by transitions. In finite control, it is
decided that “machine is in this state and it is getting this input, so it will go to this state”.
KHIT,CSE Page 6
www.Jntufastupdates.com
Formal Languages and Automata Theory – R16
3. State transition
4. Input events
1. State:
This element defines the behaviour of the system and generate action to be performed. There
are different types of states. They are 1. Start state
2. Next state
3. Accepting state
3. Dead state
4. Inaccessible state
5. Universal State
6. Existential State
Types of states:
1. Start state: State which is used to start processing of input string in finite state
machine is called as “start state” or “initial state”.
2. Next state: State which is defined by the transition function of finite state machine for
current state 𝑞𝑖 and input symbol x is called as “next state”.
𝛿 (𝑞𝑖 , 𝑥 ) → 𝑞𝑗
3. Accepting state: Once entire string is processed, state which leads to acceptance of
string is called as “Accepting state” or “final state”.
4. Dead state: A non final state of finite state machine whose transitions on every input
symbol terminates on itself is called as “dead state”.
𝑞 ∉ 𝐹 𝑎𝑛𝑑 𝛿 (𝑞𝑖 , Σ) → 𝑞𝑖
5. Inaccessible state: State which can never be reached from initial state is called
“inaccessible state” or “useless state”.
6. Equivalent state: Two states are “equivalent” or “indistinguishable”, if both
produces final states or if both produces non final states on applying same input
symbol.
𝛿(𝑞𝑖 , 𝑥 ) ∈ 𝐹 → 𝛿(𝑞𝑗 , 𝑥) ∈ 𝐹
𝛿 (𝑞𝑖 , 𝑥 ) ∈ 𝑁𝐹 → 𝛿(𝑞𝑗 , 𝑥) ∈ 𝑁𝐹
𝛿 (𝑞𝑖 , 𝑥 ) ∈ 𝑁𝐹 → 𝛿(𝑞𝑗 , 𝑥) ∈ 𝐹
2. Rules:
This element defines the conditions that are to be satisfied for enabling state transition.
3. State transition:
This element defines the change in state. i,e., moving from one state to another state is known
as transition. Transitions are represented in 3 ways. They are 1. Transition diagram
2. Transition table
3. Transition function.
KHIT,CSE Page 7
www.Jntufastupdates.com
Formal Languages and Automata Theory – R16
Types of transition:
1. Transition diagram/ Transition graph/ Transition system:
A diagrammatical representation of states and transitions is called as transition
diagram. In transition diagram, circles are used to represent states and directed arrows
are used to represent transitions between states.
Representations:
Start state
Final state
Other states
KHIT,CSE Page 8
www.Jntufastupdates.com
Formal Languages and Automata Theory – R16
Computation begins in start state with input string in input tape. The read head scans the
input from input tape and sends it to finite control.
Based on current state and input symbol of finite state machine, next state will be determined.
After processing the entire string, if the finite control enters into one of the final states, FSM
declares that string is accepted and recognizes that string belongs to the given language.,
otherwise it declares that string doesn’t belongs to the given language.
A transition system is formally defined as a directed labeled graph where each vertex is a
state, and directed edge is a transition between two states and edges are labeled with
input/output.
KHIT,CSE Page 9
www.Jntufastupdates.com
Formal Languages and Automata Theory – R16
i.e if (𝑞0 , w. 𝑞2 ) is in 𝜹. it means that the graph starts at the vertex 𝑞0 , goes along a set of
edges, and reaches the vertex 𝑞2 . The concatenation of the label of all the edges thus
encountered is w.
KHIT,CSE Page 10
www.Jntufastupdates.com
Formal Languages and Automata Theory – R16
Definition:
Deterministic Finite Automata can be defined as “it is a finite automata in which all the
moves of a machine can be uniquely determined by using current state and input symbol. i.e.,
For the given input symbol, there will be only one transition from the current state.
Mathematical representation of DFA:
Initially DFA is assumed to be in its start state 𝑞0 with its read head on leftmost symbol of
input string in input tape. The read head scans the input from input tape and sends it to finite
control.
Based on current state and input symbol of finite state machine, next state will be determined
by finite control. During each move, read head moves one position to the right.
After processing the entire string, if the DFA enters into one of the final states, the string is
accepted, otherwise the string is rejected.
KHIT,CSE Page 11
www.Jntufastupdates.com
Formal Languages and Automata Theory – R16
Design of DFAs:
1. Write the strings in the given language using the given input alphabet ∑.
2. Design DFA for the minimum string in the language.
3. At each state, for the input symbol which has no transition, put a loop over that
particular state with that input symbol.
4. If the language is satisfied for that loop on that state, then check for next state.
Otherwise, put the transition for the previous state with that input symbol.
5. If then also, it is not satisfied, then put the transition for the previous previous state
with that input symbol.
6. If it is a start state, include a new state called as dead state.
7. Repeat the steps 2-5 until each and every state in DFA is having a transition with each
and every input symbol.
Definition:
Non Deterministic Finite Automata can be defined as “it is a finite automata in which some
of the moves of a machine cannot be uniquely determined by using current state and input
symbol. i.e., For the given input symbol, there will be more than one transition from the
current state.
Mathematical representation of NFA:
Initially NFA is assumed to be in its start state 𝑞0 with its read head on leftmost symbol of
input string in input tape. The read head scans the input from input tape and sends it to finite
control.
Based on current state and input symbol of finite state machine, several choices may exist for
the next state. Then the machine chooses one of them and continues.
If the next input symbol matches, it continues. Otherwise, it chooses another way. During
each move, read head moves one position to the right.
KHIT,CSE Page 12
www.Jntufastupdates.com
Formal Languages and Automata Theory – R16
After processing the entire string, if the NFA enters into one of the final states, the string is
accepted, otherwise the string is rejected.
Design of NFAs:
1. Write the strings in the given language using the given input alphabet ∑.
2. Design NFA for the minimum string in the language.
3. Put the transition with the input symbol wherever necessary, such that all strings of
given language are accepted by NFA.
Two DFAs M1 and M2 are said to be equivalent, if the language accepted by 2 DFAs is same
irrespective of number of states. i.e., if L(M1)=L(M2), then M1 and M2 are equivalent.
Procedure:
1. Draw transition table format with input symbols and pair of states. Each pair of states
contains state from M1 and state from M2.
2. Initially take start states of M1 and M2 as a pair and generate new pair of states with
the input symbols of DFA.
3. During the process of generating new pair of states, if a pair of type (F,NF) or (NF,F)
is generated, then immediately stop the process and conclude that given DFAs are not
equivalent.
4. During the process of generating pairs of states, if a pair of type (F,F) or (NF,NF) is
generated, then repeat the process until no new pair of states are found and conclude
that given DFAs are equivalent.
Definition:
Non Deterministic Finite Automata with epsilon transitions can be defined as “it is a non
deterministic finite automata in which some of the transitions of a machine can be made
without reading any input symbol. i.e., without any input symbol (ɛ), there will be a transition
from the current state.
ɛ - transitions:
ɛ - transitions are the transitions by using which NFA can change its state without reading
any input symbol.
KHIT,CSE Page 13
www.Jntufastupdates.com
Formal Languages and Automata Theory – R16
ɛ - closure:
ɛ - closure of a state is set of all the states reachable from that state by using only ɛ -
transitions including itself.
ɛ-closure(q0)={q0,q1,q2} for
Initially NFA-ɛ is assumed to be in its start state 𝑞0 with its read head on leftmost symbol of
input string in input tape. The read head scans the input from input tape and sends it to finite
control.
Based on current state and input symbol of finite state machine, several choices may exist for
the next state. Then the machine chooses one of them and continues.
If there is no input symbol, then using epsilon transition, it moves to next state and continues.
If the next input symbol matches, it continues. Otherwise, it chooses another way. During
each move, read head moves one position to the right.
After processing the entire string, if the NFA-ɛ enters into one of the final states, the string is
accepted, otherwise the string is rejected.
Design of NFA-ɛ:
1. Write the strings in the given language using the given input alphabet ∑.
2. Design NFA- ɛ for the minimum string in the language.
3. Put the transition with the ɛ symbol wherever necessary, such that all strings of given
language are accepted by NFA-ɛ.
KHIT,CSE Page 14
www.Jntufastupdates.com
Formal Languages and Automata Theory – R16
2. Find transitions for NFA 𝜹′ with every state and every input symbol of given NFA- ɛ
using 𝜹′(𝒒𝒑 , 𝒊) = 𝜺 − 𝒄𝒍𝒐𝒔𝒖𝒓𝒆 (𝜹(𝜺 − 𝒄𝒍𝒐𝒔𝒖𝒓𝒆( 𝒒𝒑 ), 𝒊)
3. Draw the transition diagram based on transitions obtained.
4. The start state of NFA is the start state of given NFA- ɛ.
5. The final states of NFA are the final states of NFA- ɛ.
Definition:
1. Equivalence method:
Definitions:
k-equivalent:
Two states are said to be “k-equivalent” (k≥0) , if both produces final states or if both
produces non final states on applying same input of length k or less.
K=0, 0-equivalent:
The only string with length “0” is ɛ. If ɛ is applied on any state, it cannot reach a final state,
but if ɛ is applied on any state, it reaches a final state, since the ɛ- closure of any state
includes the state itself.
Therefore at level “0”, behaviour of final states differ from non final states. so, partition the
states into 2 groups, final and non final. It is denoted by 𝜋0 .
K=1, 1-equivalent:
It is denoted by 𝜋1 . Equivalence at level 1 can exist if and only if there is equivalence at level
“0”. Therefore here equivalence is to be checked among the states that were equivalent in
level 0 (subsets of 𝜋0 ). States having the same behavior will be grouped.
Procedure:
KHIT,CSE Page 15
www.Jntufastupdates.com
Formal Languages and Automata Theory – R16
For each group, write the transition table with input symbols on row side and
states on column side.
Rewrite the transition table by replacing the transition with its group number
that it falls into.
For any input symbol, if transition is made to same subset of 𝜋0 , then it cannot
be partitioned.
For any input symbol, if transition is made to different subset of 𝜋0 , then
subset is again partitioned.
4. Similarly find 2-equivalence (𝜋2 ) and so on until 𝜋𝑛−1 = 𝜋𝑛 .
5. For any input symbol, if no partitions are made on subsets of 𝜋𝑛 , then that states are
indistinguishable and these groups are the states of modified DFA.
6. Draw transition table for the minimized DFA with modified states on row side and
input symbols on column side and generate the transitions.
7. Draw transition diagram based on transition table obtained in step 6. This is the
required minimized DFA.
8. Remove any useless states to obtain optimized DFA.
2. Myhill-Nerode theorem:
1. MOORE MACHINE:
Definition:
It was proposed by Edward F. Moore. Moore machine is a finite automata with output where
output depends on present state only. In this machine, states are labeled with state name and
output.
KHIT,CSE Page 16
www.Jntufastupdates.com
Formal Languages and Automata Theory – R16
𝑀 = 𝑀𝑜𝑜𝑟𝑒 𝑀𝑎𝑐ℎ𝑖𝑛𝑒
𝑄 − 𝑓𝑖𝑛𝑖𝑡𝑒 𝑛𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑠𝑡𝑎𝑡𝑒𝑠
Σ − 𝑖𝑛𝑝𝑢𝑡 𝑎𝑙𝑝ℎ𝑎𝑏𝑒𝑡 𝑜𝑟 𝑠𝑒𝑡 𝑜𝑓 𝑖𝑛𝑝𝑢𝑡 𝑠𝑦𝑚𝑏𝑜𝑙𝑠
Δ − 𝑜𝑢𝑡𝑝𝑢𝑡 𝑎𝑙𝑝ℎ𝑎𝑏𝑒𝑡 𝑜𝑟 𝑠𝑒𝑡 𝑜𝑓 𝑜𝑢𝑡𝑝𝑢𝑡 𝑠𝑦𝑚𝑏𝑜𝑙𝑠
𝛿 − 𝑖𝑛𝑝𝑢𝑡 𝑡𝑟𝑎𝑛𝑠𝑖𝑡𝑖𝑜𝑛 𝑓𝑢𝑛𝑐𝑡𝑖𝑜𝑛 𝑑𝑒𝑓𝑖𝑛𝑒𝑑 𝑏𝑦 𝛿: 𝑄𝑋Σ → Q
𝜆 − 𝑜𝑢𝑡𝑝𝑢𝑡 𝑡𝑟𝑎𝑛𝑠𝑖𝑡𝑖𝑜𝑛 𝑓𝑢𝑛𝑐𝑡𝑖𝑜𝑛 𝑑𝑒𝑓𝑖𝑛𝑒𝑑 𝑏𝑦 𝛿: 𝑄 → Δ
𝑞0 − 𝑠𝑡𝑎𝑟𝑡 𝑠𝑡𝑎𝑡𝑒 𝑞0 ∈ 𝑄
2. MEALY MACHINE:
Definition:
It was proposed by George H. Mealy. Mealy machine is a finite automata with output where
output depends on present state and present input. In this machine, transition is labeled with
input and output.
𝑀 = 𝑀𝑜𝑜𝑟𝑒 𝑀𝑎𝑐ℎ𝑖𝑛𝑒
𝑄 − 𝑓𝑖𝑛𝑖𝑡𝑒 𝑛𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑠𝑡𝑎𝑡𝑒𝑠
Σ − 𝑖𝑛𝑝𝑢𝑡 𝑎𝑙𝑝ℎ𝑎𝑏𝑒𝑡 𝑜𝑟 𝑠𝑒𝑡 𝑜𝑓 𝑖𝑛𝑝𝑢𝑡 𝑠𝑦𝑚𝑏𝑜𝑙𝑠
Δ − 𝑜𝑢𝑡𝑝𝑢𝑡 𝑎𝑙𝑝ℎ𝑎𝑏𝑒𝑡 𝑜𝑟 𝑠𝑒𝑡 𝑜𝑓 𝑜𝑢𝑡𝑝𝑢𝑡 𝑠𝑦𝑚𝑏𝑜𝑙𝑠
𝛿 − 𝑖𝑛𝑝𝑢𝑡 𝑡𝑟𝑎𝑛𝑠𝑖𝑡𝑖𝑜𝑛 𝑓𝑢𝑛𝑐𝑡𝑖𝑜𝑛 𝑑𝑒𝑓𝑖𝑛𝑒𝑑 𝑏𝑦 𝛿: 𝑄𝑋Σ → Q
𝜆 − 𝑜𝑢𝑡𝑝𝑢𝑡 𝑡𝑟𝑎𝑛𝑠𝑖𝑡𝑖𝑜𝑛 𝑓𝑢𝑛𝑐𝑡𝑖𝑜𝑛 𝑑𝑒𝑓𝑖𝑛𝑒𝑑 𝑏𝑦 𝛿: 𝑄𝑋Σ → Δ
𝑞0 − 𝑠𝑡𝑎𝑟𝑡 𝑠𝑡𝑎𝑡𝑒 𝑞0 ∈ 𝑄
KHIT,CSE Page 17
www.Jntufastupdates.com
Formal Languages and Automata Theory – R16
KHIT,CSE Page 18
www.Jntufastupdates.com
Formal Languages and Automata Theory – R16
DFA NFA
“it is a finite automata in which all the moves “it is a finite automata in which some of the
of a machine can be uniquely determined by moves of a machine cannot be uniquely
using current state and input symbol determined by using current state and input
symbol.
DFA is formally defined as 5-tuple 𝑴 = NFA is formally defined as 5-tuple 𝑴 =
(𝑸, 𝚺, 𝜹, 𝒒𝟎 , 𝑭) where (𝑸, 𝚺, 𝜹, 𝒒𝟎 , 𝑭) where
𝑀= 𝑀=
𝐹𝑖𝑛𝑖𝑡𝑒 𝑆𝑡𝑎𝑡𝑒 𝑀𝑎𝑐ℎ𝑖𝑛 𝐹𝑖𝑛𝑖𝑡𝑒 𝑆𝑡𝑎𝑡𝑒 𝑀𝑎𝑐ℎ𝑖𝑛
𝑄 − 𝑓𝑖𝑛𝑖𝑡𝑒 𝑛𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑠𝑡𝑎𝑡𝑒𝑠 𝑄 − 𝑓𝑖𝑛𝑖𝑡𝑒 𝑛𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑠𝑡𝑎𝑡𝑒𝑠
Σ − 𝑖𝑛𝑝𝑢𝑡 𝑎𝑙𝑝ℎ𝑎𝑏𝑒𝑡 Σ − 𝑖𝑛𝑝𝑢𝑡 𝑎𝑙𝑝ℎ𝑎𝑏𝑒𝑡
𝛿 − 𝑡𝑟𝑎𝑛𝑠𝑖𝑡𝑖𝑜𝑛 𝑓𝑢𝑛𝑐𝑡𝑖𝑜𝑛 𝑑𝑒𝑓𝑖𝑛𝑒𝑑 𝑏𝑦 𝛿 − 𝑡𝑟𝑎𝑛𝑠𝑖𝑡𝑖𝑜𝑛 𝑓𝑢𝑛𝑐𝑡𝑖𝑜𝑛 𝑑𝑒𝑓𝑖𝑛𝑒𝑑 𝑏𝑦
𝛿: 𝑄𝑋Σ → Q 𝛿: 𝑄𝑋Σ ∪ {ε} → 2Q , 2Q ⊆ 𝑄
𝑞0 − 𝑠𝑡𝑎𝑟𝑡 𝑠𝑡𝑎𝑡𝑒 𝑞0 ∈ 𝑄 𝐹− 𝑞0 − 𝑠𝑡𝑎𝑟𝑡 𝑠𝑡𝑎𝑡𝑒 𝑞0 ∈ 𝑄 𝐹−
𝑠𝑒𝑡 𝑜𝑓 𝑓𝑖𝑛𝑎𝑙 𝑠𝑡𝑎𝑡𝑒𝑠 𝐹 ⊆ 𝑄 𝑠𝑒𝑡 𝑜𝑓 𝑓𝑖𝑛𝑎𝑙 𝑠𝑡𝑎𝑡𝑒𝑠 𝐹 ⊆ 𝑄
It does not allow any epsilon transitions It allows epsilon transitions
It takes less time to recognize input string. It takes more time to recognize input string.
It occupies more space. It occupies less space.
It accepts a string, if it is in one of the final It accepts a string, if some sequence of
states, after processing entire string. possible moves of a machine reaches final
state, after processing entire string.
It rejects a string, if it is in non-final states, It rejects a string, if no sequence of possible
after processing entire string. moves of a machine reaches final state, after
processing entire string.
It is bigger than NFA. It is smaller than DFA.
KHIT,CSE Page 19
www.Jntufastupdates.com