Automata Notes
Automata Notes
Theory of Automata
Theory of automata is a theoretical branch of computer science and mathematical. It is the study
of abstract machines and the computation problems that can be solved using these machines. The
abstract machine is called the automata. The main motivation behind developing the automata
theory was to develop methods to describe and analyse the dynamic behaviour of discrete
systems.
This automaton consists of states and transitions. The State is represented by circles, and
the Transitions is represented by arrows.
Automata is the kind of machine which takes some string as input and this input goes through a
finite number of states and may enter in the final state.
There are the basic terminologies that are important and frequently 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:
1. ∑ = {a, b}
2.
3. ∑ = {A, B, C, D}
4.
5. ∑ = {0, 1, 2}
6.
7. ∑ = {0, 1, ....., 5]
8.
9. ∑ = {#, β, Δ}
String:
It is a finite collection of symbols from the 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.....}.
o A string with zero occurrences of symbols is known as an empty string. It is represented
by ε.
o The number of symbols in a string w is called the length of a string. It is denoted by |w|.
Language:
A language is a collection of appropriate string. A language which is formed over Σ can
be Finite or Infinite.
Example: 1
Example: 2
Regular Expression
o The language accepted by finite automata can be easily described by simple expressions
called Regular Expressions. It is the most effective way to represent any language.
o The languages accepted by some regular expression are referred to as Regular languages.
o A regular expression can also be described as a sequence of pattern that defines a string.
o Regular expressions are used to match character combinations in strings. String searching
algorithm used this pattern to find the operations on a string.
For instance:
In a regular expression, x* means zero or more occurrence of x. It can generate {e, x, xx, xxx,
xxxx, .....}
In a regular expression, x+ means one or more occurrence of x. It can generate {x, xx, xxx,
xxxx, .....}
Union: If L and M are two regular languages then their union L U M is also a union.
1. 1. L U M = {s | s is in L or s is in M}
Intersection: If L and M are two regular languages then their intersection is also an intersection.
1. 1. L ⋂ M = {st | s is in L and t is in M}
Kleen closure: If L is a regular language then its Kleen closure L1* will also be a regular
language.
Solution:
All combinations of a's means a may be zero, single, double and so on. If a is appearing zero
times, that means a null string. That is we expect the set of {ε, a, aa, aaa, ....}. So we give a
regular expression for this as:
1. R = a*
That is Kleen closure of a.
Example 2:
Write the regular expression for the language accepting all combinations of a's except the null
string, over the set ∑ = {a}
Solution:
R = a+
Example 3:
Write the regular expression for the language accepting all the string containing any number of
a's and b's.
Solution:
1. r.e. = (a + b)*
This will give the set as L = {ε, a, aa, b, bb, ab, ba, aba, bab, .....}, any combination of a and b.
The (a + b)* shows any combination with a and b even a null string.
Finite Automata
Formal Definition of FA
A finite automaton is a collection of 5-tuple (Q, ∑, δ, q0, F), where:
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.
Types of Automata:
There are two types of finite automata:
1. DFA
DFA refers to deterministic finite automata. Deterministic refers to the uniqueness of the
computation. In the DFA, the machine goes to one state only for a particular input character.
DFA does not accept the null move.
2. NFA
NFA stands for non-deterministic finite automata. It is used to transmit any number of states for
a particular input. It can accept the null move.
Transition Diagram
A transition diagram or state transition diagram is a directed graph which can be constructed as
follows:
1. In DFA, the input to the automata can be any string. Now, put a pointer to the start state q and
read the input string w from left to right and move the pointer according to the transition
function, δ. We can read one symbol at a time. If the next symbol of string w is a and the pointer
is on state p, move the pointer to δ(p, a). When the end of the input string w is encountered, then
the pointer is on some state F.
2. The string w is said to be accepted by the DFA if r ∈ F that means the input string w is
by DFA if r ∉ F.
processed successfully and the automata reached its final state. The string is said to be rejected
Example 1:
DFA with ∑ = {0, 1} accepts all strings starting with 1.
Solution:
The finite automata can be represented using a transition graph. In the above diagram, the
machine initially is in start state q0 then on receiving input 1 the machine changes its state to q1.
From q0 on receiving 0, the machine changes its state to q2, which is the dead state. From q1 on
receiving input 0, 1 the machine changes its state to q1, which is the final state. The possible
input strings that can be generated are 10, 11, 110, 101, 111......., that means all string starts with
1.
Example 2:
NFA with ∑ = {0, 1} accepts all strings starting with 1.
Solution:
The NFA can be represented using a transition graph. In the above diagram, the machine initially
is in start state q0 then on receiving input 1 the machine changes its state to q1. From q1 on
receiving input 0, 1 the machine changes its state to q1. The possible input string that can be
generated is 10, 11, 110, 101, 111......, that means all string starts with 1.
Transition Table
The transition table is basically a tabular representation of the transition function. It takes two
arguments (a state and a symbol) and returns a state (the "next state").
Example 1:
Solution:
→q0 q1 q2
q1 q0 q2
*q2 q2 q2
Explanation:
o In the above table, the first column indicates all the current states. Under column 0 and 1,
the next states are shown.
o The first row of the transition table can be read as, when the current state is q0, on input 0
the next state will be q1 and on input 1 the next state will be q2.
o In the second row, when the current state is q1, on input 0, the next state will be q0, and
on 1 input the next state will be q2.
o In the third row, when the current state is q2 on input 0, the next state will be q2, and on 1
input the next state will be q2.
o The arrow marked to q0 indicates that it is a start state and circle marked to q2 indicates
that it is a final state.
Example 2:
Solution:
→q0 q0 q1
q1 q1, q2 q2
q2 q1 q3
*q3 q2 q2
Explanation:
o The first row of the transition table can be read as, when the current state is q0, on input 0
the next state will be q0 and on input 1 the next state will be q1.
o In the second row, when the current state is q1, on input 0 the next state will be either q1
or q2, and on 1 input the next state will be q2.
o In the third row, when the current state is q2 on input 0, the next state will be q1, and on 1
input the next state will be q3.
o In the fourth row, when the current state is q3 on input 0, the next state will be q2, and on
1 input the next state will be q2.
o NFA stands for non-deterministic finite automata. It is easy to construct an NFA than
DFA for a given regular language.
o The finite automata are called NFA when there exist many paths for specific input from
the current state to the next state.
o Every NFA is not DFA, but each NFA can be translated into DFA.
o NFA is defined in the same way as DFA but with the following two exceptions, it
contains multiple next states, and it contains ε transition.
In the following image, we can see that from state q0 for input a, there are two next states q1 and
q2, similarly, from q0 for input b, the next states are q0 and q1. Thus it is not fixed or determined
that with a particular input where to go next. Hence this FA is called non-deterministic finite
automata.
δ: Q x ∑ →2Q
where,
Example 1:
1. Q = {q0, q1, q2}
2. ∑ = {0, 1}
3. q0 = {q0}
4. F = {q2}
Solution:
Transition diagram:
Transition Table:
→q0 q0, q1 q1
q1 q2 q0
*q2 q2 q1, q2
In the above diagram, we can see that when the current state is q0, on input 0, the next state will
be q0 or q1, and on 1 input the next state will be q1. When the current state is q1, on input 0 the
next state will be q2 and on 1 input, the next state will be q0. When the current state is q2, on 0
input the next state is q2, and on 1 input the next state will be q1 or q2.
Example 2:
NFA with ∑ = {0, 1} accepts all strings with 01.
Solution:
Transition Table:
Present State Next state for Input 0 Next State of Input 1
→q0 q1 ε
q1 ε q2
*q2 q2 q2
Example 3:
NFA with ∑ = {0, 1} and accept all string of length atleast 2.
Solution:
Transition Table:
→q0 q1 q1
q1 q2 q2
*q2 ε ε
Example 1:
Design a NFA for the transition table as given below:
Present State 0 1
q1 q3 ε
q2 q2, q3 q3
→q3 q3 q3
Solution:
The transition diagram can be drawn by using the mapping function as given in the table.
Here,
Solution:
Hence, NFA would be:
Example 3:
Design an NFA with ∑ = {0, 1} in which double '1' is followed by double '0'.
Solution:
Then,
Now before double 1, there can be any string of 0 and 1. Similarly, after double 0, there can be
any string of 0 and 1.
1. q0 → q1 → q2 → q3 → q4 → q4 → q4 → q4
Example 4:
Design an NFA in which all the string contain a substring 1110.
Solution:
The language consists of all the string containing substring 1010. The partial transition diagram
can be:
Now as 1010 could be the substring. Hence we will add the inputs 0's and 1's so that the
substring 1010 of the language can be maintained. Hence the NFA becomes:
Transition table for the above transition diagram can be given below:
Present State 0 1
→q1 q1 q1, q2
q2 q3
q3 q4
q4 q5
*q5 q5 q5
Example 5:
Design an NFA with ∑ = {0, 1} accepts all string in which the third symbol from the right end is
always 0.
Solution:
Thus we get the third symbol from the right end as '0' always. The NFA can be:
The above image is an NFA because in state q0 with input 0, we can either go to state q0 or q1.