ATCD UT1 Material - 220816 - 203517
ATCD UT1 Material - 220816 - 203517
The central concepts of Automata Theory: Alphabet, Strings, Language Definitions with
examples, Operations on Languages, Language Recognizers, Finite Automaton Model.
Deterministic and Non Deterministic Finite Automata: Deterministic finite automaton,
Transition Tables and Diagrams, Types of States, Non-deterministic finite automaton.
Eg: a, b, c……..z
0, 1, 2……….9
+, -, % ….special characters
1.0.2 Alphabet: An alphabet is a finite, non-empty set of symbol. It is denoted by sigma (Σ).
1.0.3 String: A string is finite sequence of symbols chosen from alphabet and denoted by
symbol w.
Example:
1. Empty String: The empty string is the string with zero occurrences of symbol. It is denoted
by “ε”.
Example:
2. Length of string: It is the number of symbols in the string and it is denoted by |ω|.
Example:
3. Prefix: The prefix of any string is any number of leading symbols of string.
1
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
4. Suffix: Suffix of any string is any number of trailing symbol of string.
Example:
Example:
6. Concatenation of String: if w and x are two strings then the concatenation of two strings is
denoted by wx.
Example:
If “Σ” is an alphabet, set of all strings of certain length from that alphabet by using exponential
notation. It is denoted by Σk is the set of strings of length k.
1.0.5 Kleen Closure: The set of strings over an alphabet Σ is usually denoted by Σ * = kleen
closure.
1.0.6 Kleen plus: The set of all strings over an alphabet Σ excluding ε is usually denoted by ε + =
kleen plus.
2
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
1.1 Language:
Note that language is formed by appropriate strings and strings are formed by alphabets.
Examples:
2. Σ = {0, 1}
3. Σ = {0, 1, 2… 9}
6. The set of string consisting of n 0’s followed by n 1’s {ε, 01, 0011, 000111……….}
Operations on Languages:
1. Union: If L1 and L2 are two languages then, Union of two languages is denoted as L1 υ L2. i.e.,
L1 υ L2 = {x, y | x ϵ L1 and y ϵ L2}.
Example:
Example:
Example:
3
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
L = {ab} then,
L1 = {ab}
L2 = L1.L1 = {abab}
L3 = L1.L1.L1 = {ababab}
L4 = L1.L1.L1.L1 = {abababab}
∞
L* = ⋃∞ 𝒊
𝒊=𝟎 𝑳 = L υ L υ L υ L …………L
0 1 2 3
∞
Example: L+ = ⋃∞ 𝒊
𝒊=𝟏 𝑳 = L υ L υ L …………L
1 2 3
Chomsky Hierarchy represents the class of languages that are accepted by the different
machines. According to Chomsky hierarchy, grammar is divided into 4 types as follows:
4
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
This is a hierarchy. Therefore every language of type 3 is also of type 2, 1 and 0. Similarly, every
language of type 2 is also of type 1 and type 0, etc.
1. Type 0 Grammar:
Type 0 grammar is known as Unrestricted grammar. There is no restriction on the grammar rules
of these types of languages. These languages are also known as the Recursively Enumerable
languages. These languages can be efficiently modeled by Turing machines.
Example:
bAa → aa
S→s
2. Type 1 Grammar:
Type 1 grammar is known as Context Sensitive Grammar. The context sensitive grammar is used
to represent context sensitive language. The language generated by the grammar is recognized by
the Linear Bound Automata. The context sensitive grammar follows the following rules:
The context sensitive grammar may have more than one symbol on the left hand side of
their production rules.
The number of symbols on the left-hand side must not exceed the number of symbols on
the right-hand side.
The rule of the form A → ε is not allowed unless A is a start symbol. It does not occur on
the right-hand side of any rule.
The Type 1 grammar should be Type 0. In type 1, Production is in the form of α → β,
where |α| ≤ |β|.
Example:
S → AT
T → xy
A→a
3. Type 2 Grammar:
Type 2 Grammar is known as Context Free Grammar. Type2 grammars generate context free
languages. The language generated by the grammar is recognized by pushdown automata. Type
2 should be type 1. The production rule is of the form: α → β, where |α| ≤ |β|, αϵV, |α| = 1.
5
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
Example:
A → aBb
A→b
B→a
4. Type 3 Grammar:
Type 3 Grammar is known as Regular Grammar. Regular languages are those languages which
can be described using regular expressions. These languages can be modeled by NFA or DFA.
Type 3 is most restricted form of grammar. The Type 3 grammar should be Type 2 and Type 1.
Type 3 should be in the form of α → β.
Example:
M = (Q, Σ, δ, q0, F)
Where
6
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
q0: The initial/starting state, q0 is in Q
1. Transition Diagrams:
It is a directed graph associated with the vertices of the graph corresponds to the state of the
finite automata.
Example: we have 3 states Q0, Q1 and Q2 along with 2 inputs a and b as shown below. Q0 is
the initial state and Q1 is the final state. Which is accepting any string starting with a.
2. Transition Table:
It is basically a tabular representation, of the transition function that takes two arguments
(a state and a symbol) and returns a value (the next state).
Rows corresponds to states
Column corresponds to input symbols
Entries corresponds to next states
The start state is marked with an arrow (→)
The accept state is marked with a star (*)
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.
8
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
1.4 Types of Finite Automata:
DFA refers to deterministic finite automata. The finite automata are called deterministic
finite automata if the machine is read an input string one symbol at a time.
In DFA, there is only one path for specific input from the current state to the next
state.
DFA does not accept the null move, i.e., the DFA cannot change state without any input
character.
DFA can contain multiple final states. It is used in Lexical Analysis in Compiler.
Example: In the following diagram, we can see that from state 0 for input 0, there is only one
path which is going to 1. Similarly, from 0, there is only one path for input 1 going to 0.
One important thing to note is, there can be many possible DFAs for a pattern. A DFA with a
minimum number of states is generally preferred.
9
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
Q: finite set of states
F: final state
δ: Transition function
δ: Q x ∑→Q
Example 1:
∑ = {0, 1}
q0 = {q0}
F = {q2}
Solution:
Transition Diagram -
Transition Table:
Present State Next state for Input 0 Next state for Input 1
→q0 q0 q1
q1 q2 q1
*q2 q2 q2
10
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
Example 2:
Solution:
Example 3:
Solution:
Example 4:
Design a FA with ∑ = {0, 1} accepts those string which starts with 1 and ends with 0.
Solution:
The FA will have a start state q0 from which only the edge with input 1 will go to the next state.
Example 5:
Solution:
11
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
Example 6:
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:
Step -1:
Make initial state “q0” then it is that possibility that there would not be any “1” or “0” as, empty
string contain even number of 0’s and even number of 1’s.
Step -2:
Create transition of input alphabet ‘1’ from state “q0” to state “q1” and input alphabet ‘0’ from
state “q0” to state “q2”.
Step -3:
After number of ‘1’ at “q1” are odd 1’s. So, send input alphabet ‘1’ from state “q1” to state “q0“
and input alphabet ‘0’ from state “q1” to state “q3“.
Step -4:
After step 3 we have got an even number of 1’s at “q0” and an odd number of 0’s and 1’s “q1,
q2, q3”. Now send input alphabet ‘0’ from state “q2” to state “q0“ and input alphabet ‘1’ from
state “q2” to state “q3“.
Step -5:
At this step, we complete the over the machine with “q3“ so that after the transition the machine
will accept the string the number of ‘1’ and ‘0’ are even. As last even number of ‘1’ and ‘0’
reach to “q0” so make the state “q0” be the final state.
12
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
Transition table of above DFA:
In above table -> represents initial state and * represents final state.
Example 7:
Design FA with ∑ = {0, 1} accepts the set of all strings with three consecutive 0's.
Solution:
The strings that will be generated for this particular languages are 000, 0001, 1000, 10001, .... in
which 0 always appears in a clump of 3. The transition graph is as follows:
Example 8:
Design a DFA L(M) = {w | w ε {0, 1}*} and W is a string that does not contain consecutive 1's.
Solution:
13
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
The stages q0, q1, q2 are the final states. The DFA will generate the strings that do not contain
consecutive 1's like 10, 110, 101..... etc.
Example 9:
Design a FA with ∑ = {0, 1} accepts the strings with an even number of 0's followed by single 1.
Solution:
Example 10:
Design a DFA accepting the set of all strings such that the number of 0’s is a multiple of 3 over
the alphabet {0, 1}.
Step-1:
Make initial state “A” then it is the possibility that there would not be any ‘0’ but have only ‘1’
in the string which is acceptable because 0 is divisible by 3.So, in this case, nay number of 1’s
can be present here and for this put self-loop of ‘1’ on initial state “A”.
Step-2:
Create transition of input alphabet ‘0’ from state “A” to state “B”.
14
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
Step-3:
After one ‘0’ any number of 1’s can be present i.e, no ‘1’ or more than one ‘1’.For this put self-
loop of ‘1’ on state “B”.
Step-4:
Now create transition of input alphabet ‘0’ from state “B” to state “C” and after two 0’s any
number of 1’s can be found in the string and for this put self-loop of ‘1’ on initial state “C”.
Step-5:
Before transition of third ‘0’ we need to think about the logic so that after this transition the
machine will accept string that have number of zeros divisible by 3.For this transit ‘o’ from state
“C” to state “A”.AS third zero is reaching to state “A” so make state “A” be final state.
Transition Table:
15
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
1.4.2 NFA (Non-Deterministic finite automata):
NFA stands for non-deterministic finite automata. It is easy to construct an NFA than
DFA for a given regular language.
The finite automata are called NFA when there exist many paths for specific input
from the current state to the next state.
Every NFA is not DFA, but each NFA can be translated into DFA.
NFA is defined in the same way as DFA but with the following two exceptions, it
contains multiple next states, and it contains ε transition.
Example: In the below NFA there are multiple paths for the input string “00”. Since one of the
paths leads to a final state, “00” is accepted by the above NFA.
NFA also has five states same as DFA, but with different transition function, as shown follows:
δ: Q x ∑ →2Q
where,
F: final state
δ: Transition function
16
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
4. The final state is denoted by the double circle.
Example 1:
∑ = {0, 1}
q0 = {q0}
F = {q2}
Solution:
Transition diagram:
Transition Table:
Solution:
Transition Table:
17
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
Example 3:
Solution:
Transition Table:
Example 4:
Solution:
The transition diagram can be drawn by using the mapping function as given in the table.
18
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
Example 5:
Design an NFA with ∑ = {0, 1} accepts all string ending with 01.
Solution:
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. Hence the NFA becomes
q0 → q1 → q2 → q3 → q4 → q4 → q4 → q4
Example 4:
Solution:
19
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
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:
= δ(q1, 100)
= δ(q2, 00)
Got stuck! As there is no path from q2 for input symbol 0. We can process string 111010 in
another way.
= δ(q3, 100)
= δ(q4, 00)
= δ(q5, 0)
= δ(q5, ε)
As state q5 is the accept state. We get the complete scanned, and we reached to the final state.
20
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
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.
21
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.