You are on page 1of 25

CHAPTER ONE

INTRODUCTION
1.1. What is automata and complexity theory?
Automata theory is the study of abstract machines and automata, as well as the computational
problems that can be solved using them. It is a theoretical branch of Computer Science and
mathematics and deals with the study of complex computational problems and abstract
machines. An automaton (automata in plural) is an abstract self-propelled computing device
which follows a predetermined sequence of operations automatically. An automaton is a
construct that possesses all the indispensable features of a digital computer. It accepts input,
produces output, may have some temporary storage, and can make decisions in transforming the
input into the output.
Automata theory is the core of computer science as a subject matter that studies properties of
various types of automata
- Automata theory presents many useful models for software and hardware
- In compilers we use finite automata for lexical analyzers, and push down automatons for
parsers.
- In search engines, we use finite automata to determine tokens in web pages.
- Finite automata model protocols, electronic circuits.
- Context free grammars are used to describe the syntax of essentially every programming
language.
- Automata theory offers many useful models for natural language processing.
Complexity theory is concerned with the resources, such as time and space, needed to solve
computational problems. In complexity theory, the objective is to classify problems as easy
problems and hard problems. Complexity theory considers not only whether a problem can be
solved at all on a computer, but also how efficiently the problem can be solved. Two major
aspects are considered: time complexity and space complexity, which are respectively how many
steps does it take to perform a computation, and how much memory is required to perform that
computation.
Formal languages and automata theory is based on mathematical computations. These
computations are used to represent various mathematical models. In this course we will study
many interesting models such as finite automata, push down automata and Turing machines.
This course is a fundamental course, and it is very close to the subjects like compilers design,
operating system, and system software and pattern recognition system. The automata theory is a
theory of models that is a working of every process can be represented by means of models.
1.1.1. Alphabets and strings
The basic terms that provide the theory of automata include alphabets, strings, language etc.
Alphabets:
An alphabet is a finite set of non-empty symbols. It is denoted by sigma (Σ).
- Σ = {0,1}, the set of binary numbers.
- Σ = {a, b, c, d,…,z}, the set of all lower case alphabets
- Σ = {A, B, C, D,…,Z}, the set of all upper case alphabets
- Σ = {0,1,2,3,4,5,6,7,8,9} , is an alphabet represent digits
1
- ∑ = {a-z, A-Z, 0-9} represents alphanumeric alphabets
- Σ = {0,1,2,3,…..} , is not an alphabet because it is infinite
- Σ = { } , is not an alphabet because it is empty
Symbols: An abstract entity that has no meaning by itself, Letters from various alphabets, digits
and special characters are the most commonly used symbols.
Strings:
A string or word is a finite sequence of symbols chosen from some alphabet. For example, the
string w =10101 is a string over Σ = {0, 1}. An infinite sequence of letters may be constructed
from elements of an alphabet as well. For example, If ∑ = {a, b}, various strings that can be
generated from Σ are {ab, aa, aaa, bb, bbb, ba, aba.....}.
Let Σ be an alphabet, a non-empty finite set. Elements of Σ are called symbols or characters. A
string (or word) over Σ is any finite sequence of characters from Σ. For example, if Σ = {0, 1},
then 0101 is a string over Σ.
Empty String: Empty string is a string over Σ with zero occurrences of symbols. It is denoted by
ε (Epsilon) or λ.
Length of a String: The length of a string is the number of characters in the string (the length of
the sequence) and can be any non-negative integer. The empty string is the unique string over Σ
of length 0, and is denoted ε or λ.
The number of symbols in a string w is called the length of a string. It is denoted by |w|.
Examples − If w = ‘cabcad’, |w|= 6 If |w|= 0, it is called an empty string (Denoted by λ or ε)
The length of string |ab| = 2, |b| = 1, || = 0
Powers of an alphabet: If  is an alphabet, the set of all strings of a certain length from the
alphabet by using an exponential notation. k is the set of strings of length k from . That is the
set of all strings over Σ of length k is denoted Σk . Note that Σ0 = {ε} for any alphabet Σ.
Example : Let  = {0,1}. 0 = {} 1 = {0,1} 2 = {00,01,10,11}
- The set of all strings over an alphabet is denoted by *.
- * = 0 ∪ 1 ∪ 2 ∪ …
- + = 1 ∪ 2 ∪ … ……. - set of nonempty strings
-  = U { Ꜫ}
* +

Example : {0,1}* ={Ꜫ, 0,1,00,01,10,11,000…..}


{0,1}+ ={0,1,00,01,10,11,000…..}
Operations on strings
Concatenation of strings: The concatenation of two strings is the string formed by writing the
first, followed by the second, with no intervening space. Concatenation of strings is denoted by
◦. That is, if w and x are strings, then wx is the concatenation of these two strings.
Example: The concatenation of computer and science is computerscience.
Let x=0100101 and y= 1111 then x ◦ y=01001011111
String Reversal: Reversing a string means writing the string backwards. This is also known as
Transpose of string. It is denoted by wR .

2
For any string w = x1 x2 x3 … xn-1 xn the reversal of the string is w R = xn xn-1 … x3 x2 x1. For
example reverse of 1101 is 1011. The Reverse of the string abcd is dcba.
If w= wR , then that string is called palindrome.
Palindrome of string is a property of a string in which string can be read from left to right as
well as from right to left. Example: radar, madam
Substring: A substring is a part of a string.
Example: If abcd is string then possible substrings are ε,a,b,c,d,ab,bc,cd,abc,bcd are proper
substrings for the given string
The string x is a substring of string w if it is a contiguous sequence of characters in w. If |x| < |w|,
it is a proper substring.
Note :
- Every string is a substring of itself.
- The empty string e is a substring of every string.
A prefix of a string is any number of leading symbols of that string.
A suffix of a string is any number of trailing symbols.
Example 1: String abc has prefixes ε, a, ab, and abc; its suffixes are ε, c, bc, and abc.
A prefix or suffix of a string, other than the string itself, is called a proper prefix or suffix.
For example 2: if w = abbab, then {λ, a, ab, abb, abba, abbab} is the set of all prefixes of w,
while bab, ab, b are some of its suffixes.
- p is a prefix of t if t = px
- p is a proper prefix of t iff: p is a prefix of t and p≠t.
Note
o Every string is a prefix of itself.
o The empty string e is a prefix of every string.
Ex: The prefixes of abbb are: e, a, ab, abb, abbb. The proper prefixes of abbb are: e, a, ab, abb.
- s is a suffix of t if t = xs
- s is a proper suffix of t iff: s is a suffix of t and s ≠ t.
- Note:
o Every string is a suffix of itself.
o The empty string e is a suffix of every string.
Ex: The suffixes of abbb are: e, b, bb, bbb, abbb. The proper suffixes of abbb are: e, b, bb, bbb.

1.1.2. Languages and Grammars


Language:
A language is defined very generally as a subset of ∑*. A string in a language L will be called a
sentence of L. This definition is quite broad; any set of strings on an alphabet ∑ can be
considered a language. A set of strings that are chosen from * is called as a language. If  is
an alphabet, and L ⊆ * , then L is a language over . A language over  may not include
strings with all symbols of .
Language is formed by appropriate strings and strings are formed by alphabets. Some
Languages:

3
- The language of all strings consisting of n 0’s followed by n 1’ for some n≥0 : { , 01, 0011,
000111, …}
- The set of strings of 0’s and 1’s with an equal number of each: {ε, 01, 10, 0011, 0101, 1001}
- The set of binary values whose value is prime: {10, 11, 101, 111, 1011,. . .}
- * is a language for any alphabet Σ
- ∅- Empty set is a language. The empty language is denoted by ∅.
- The set {} is a language over any alphabet Σ , {} is not equal to the empty language.
- The set of all identifiers in a programming language is a language.
- The set of all syntactically correct C++ programs is a language.
Set-Formers to Define Languages:
A set-former is a common way to define a language
Set-former: {w | something about w}
{w | w consists of equal number of 0’s and 1’s}
{w | w is a binary integer that is prime}
Sometimes we replace w with an expression as
{0n1n | n≥1}
{0i1j | 0 ≤ i ≤ j}
Example: if ∑= {0,1} is a alphabet then
L1 = {0, 01, 012 , 013 , …}: L1 consist of all the strings starting with a 0 followed by any number of 1
L2 = {0m 1m : m>0} : L2 consist of words beginning with one or more 0’s followed by same
number of 1’s.
L3 = {0m 1n :m>0,n>0} : L3 consist of words beginning with one or more 0’s followed by one or
more 1’s.
L4 = {ε} : L4 is an empty language.
L={Ꜫ,0,00,000------} Here the language L is defined as 'any number of Zeros'
Operations on Languages
Since languages are set of strings we can apply set operations to languages.
Union : If L1 and L2 are two languages then the union of L1 and L2 denoted by L1 ∪ L2, any
word x ∈ L1 ∪ L2 iff x ∈ L1 or x ∈ L2.
Example: {0, 11, 01, 011} ∪ {1, 01, 110} = {0, 11, 01, 011, 11,1}
Intersection: If L1 and L2 are two languages then the intersection of L1 and L2 denoted by L1 ∩
L2, any word x ∈ L1 ∩ L2 iff x ∈ L1 and x ∈ L2
Example: {0, 11, 01, 011 } ∩ {1, 01, 110 } = { 01 }
Complement: Usually, ∑ * is referred as the universe of all the languages over the alphabet
over ∑. So complement of any language is taken with respect to ∑ *. Thus for a language L, the
complement is Lത = {x ∈ ∑ * and x ∉ L}.
Example: Let L ={x : |x| is even}. Then its complement is the language Lത ={x∈∑ *: |x| is odd }.
Similarly we can define other usual set operations on languages like relative complement,
symmetric difference, etc. Example: If ∑={a,b} and L={a,b,aa}then
L¯=∑*-L={ε,a,b,aa,bb,ab.......}-{a,b,aa}={ε,bb,ab,ba.........}

4
Reversal of a language: The reversal of a language L, denoted as LR, is defined as LR ={wR:w ∈ L}
Example : 1. If L = {0, 01, 011}. Then LR = {0, 10, 110 }.
2.If L = { an bn : n is an integer }. Then LR = { bn an : n is an integer }.
Concatenation: The concatenation of languages L1 and L2 over an alphabet ∑ is defined as
L1L2 = { xy : x ∈ L1 and y ∈ L2 }
Example: if L1 = {a, ab} and L2 = {b, ba } then L1L2 = {ab, aba, abb, abba}.

Some Properties of language concatenation


1. L1L2 ≠ L2 L1 in general.
2. L∅ = ∅
3. L{ε} = L = {ε}L
The operation Ln denotes the concatenation of L with itself n times. This is defined formally as
follows:
L0 = {ε}
Ln = LLn-1
Example: if L = {0, 01}. Then according to the definition, we have
L0 = {ε}
L1 = {0, 01}
L2 = {0, 01}{0, 01} = {00, 001, 010, 0101}
L3 = {0, 01}{00, 001, 010, 0101} = {000, 0001, 0010, 00101, 0001, 00101, 01001, 010101}
Kleene's Star operation:
The Kleene star operation on a language L, denoted as L* is defined as follows:
Kleene star closure, L* = ∪ Lk = L0 ∪ L1 ∪ L2 ∪ … ∪ Ln ∪ … = {x: x is the concatenation of zero or
more strings from L}

Also
The positive closure, L+ = L1 ∪ L2 ∪ … ∪ Ln ∪ …

Example: If L = { a, ab }. Then we have,


L* = L0 ∪ L1 ∪ L 2 ∪ … = {Ꜫ} ∪ {a, ab} ∪ {aa, aab, aba, abab} ∪ …
L = L ∪ L ∪ … ∪ L ∪ … = {a, ab} ∪ {aa, aab, aba, abab} ∪ …
+ 1 2 n

Example : Let L1 = {10, 1} Then


L* = L0 U L1 U L2.................. = {ϵ,10,1,1010,101,110,11010,…}
L+ = L1 U L2 U L3...................= {10,1,1010,101,110,11010,…}

5
Exercise
1.Construct the power-set for the following sets.
a) {a, b}
b) {0, 1} ∪ {1, 2}
c) {0, 1, 2, 3, 4} ∩{1, 3, 5, a}
2. Find a possible alphabet Σ for the following languages. (i) The language L = {oh, ouch, ugh}
(ii) The language L = {apple, pear, 4711} (iii) The language of all binary strings
3.Describe what the Kleene star operation ∗ over the following alphabets produces. (i) Σ = {0, 1}
(ii) Σ = {a} (iii) Σ = ∅ (the empty alphabet).
Solution
1.Construct the power-set for the following sets. a) 22 = {∅, {a}, {b}, {a, b}} b) {0, 1} ∪ {1, 2}
= {0, 1, 2}= 23= {∅, {0},{1}, {2}, {0,1}, {0,2}, {1, 2}, {1,2,3}} c) {0, 1, 2, 3, 4} ∩{1, 3, 5, a} =
{1, 3}= 22= {∅, {1}, {3}, {1, 5}}
2.Find a possible alphabet Σ for the following languages.
i)Σ = {o, h, u, c, g}
ii)Σ = {a, p, l, e, r, a, 4, 7, 1}
iii)Σ = {0, 1}
3. Describe what the Kleene star operation ∗ over the following alphabets produces.
(i)Σ = {0, 1}* = All binary string {ε, 0, 1, 01, 001, 1101100, …} (ii) Σ = {a}*= All strings which
contains nothing but a’s (including the empty string) {ε, a, aa, aaa, aaaa, aaaaa, …} (iii) Σ = ∅*
(the empty alphabet). = The language which contains only empty string
Grammar:
A grammar is a mechanism used for describing languages. This is one of the most simple but yet
powerful mechanism. In everyday language, like English, we have a set of symbols (alphabet), a
set of words constructed from these symbols, and a set of rules using which we can group the
words to construct meaningful sentences. The grammar for English tells us what are the words in
sentences and the rules to construct sentences. It also tells us whether a particular sentence is
well-formed (as per the grammar) or not. These concepts are generalized in formal language
leading to formal grammars. The word 'formal' here refers to the fact that the specified rules for
the language are explicitly stated in terms of what strings or symbols can occur.
A formal grammar (sometimes simply called a grammar) is a set of rules for forming strings in a
formal language. The rules describe how to form strings from the language's alphabet that are
valid according to the language's syntax. A grammar does not describe the meaning of the
strings or what can be done with them in whatever context- only their form.
A formal grammar is a set of rules for rewriting strings, along with a "start symbol" from which
rewriting must start. Therefore, a grammar is usually thought of as a language generator.
However, it can also sometimes be used as the basis for a "recognizer"—a function in computing
that determines whether a given string belongs to the language or is grammatically incorrect.
The notion of Grammar is related to studies in natural languages. These Linguists were
concerned with:
- Defining the valid sentences of a Language;
- Providing a structural definition of such valid sentences.

6
Formal definitions of a Grammar:
A grammar G is defined as a quadruple: G = (N, Σ, P, S)
- N is a non-empty finite set of non-terminals or variables. This symbols may be rewritten using
the rules of the grammar. We generally use capital letters as non-terminals symbols.
- Σ is a non-empty finite set of terminal symbols such that N∩Σ= (disjoint set). This symbols are
elements of Σ and cannot be rewritten. We generally use lower case symbols to refer to terminals.
- S ∈ N, is a special non-terminal (or variable) called the start symbol, and it provides the
starting point for derivations.
- P ⊆ (N ∪ Σ)+ x ( N ∪ Σ)* is a finite set of production rules. The production rules specify
how the grammar transforms one string to another.
The binary relation defined by the set of production rules is denoted by →, i.e. x→ y iff (x, y) ∈ P.
In other words, P is a finite set of production rules of the form x→y, where x⊆(N∪Σ)+ and
y⊆(N∪Σ)*. This statement can be described as P is a finite set of productions, each of the form x→y,
where x and y are strings over Σ ∪ V and x ≠ε
In grammar, we have at least one non-terminal on the left mapping to anything on the right. The
symbol(s) on the left-hand side of a rule is often referred to as the parent; and any non-terminals
on the right-hand side are called the daughters or children.
A grammar is a set of productions of the form x → y. The strings x and y can contain both
lowercase and uppercase letters; x cannot be empty, but y can be ε. One uppercase letter is
designated as the start symbol (conventionally, it is the letter S).
Given a string xay , we say that the production rule a→ b is applicable to this string, to rewrite
the a (in xay ) to b obtaining a new string xby . We say that xay derives xby and is denoted as
xay ⇒ xby.
Successive strings are derived by applying the productions rules of the grammar in any arbitrary
order. A particular rule can be used if it is applicable, and it can be applied as many times as
described.
We write a b if the string b can be derived from the string a in zero or more steps; a b if b
can be derived from a in one or more steps.
By applying the production rules in arbitrary order, any given grammar can generate many
strings of terminal symbols starting with the special start symbol, S, of the grammar. The set of
all such terminal strings is called the language generated (or defined) by the grammar.
Formally, for a given grammar G = (N, Σ, P, S) the language generated by G is
L(G) = { w ∈ Σ * | S w } . That is w ∈ L(G) iff S w.
If w ∈ L(G), we must have for some n≥0, S= a1⇒a2⇒a3⇒…⇒an = w denoted as a derivation
sequence of w, The strings S=a1, a2, α3, …αn = w are denoted as sentential forms of the
derivation.
Example: Consider the grammar G = (N, Σ, P, S), where N = {S}, Σ={a, b} and P is the set of
the production rules :{ S→ab, S→aSb}
Some terminal strings generated by this grammar together with their derivation is given below.

7
S ⇒ab
S ⇒aSb⇒aabb
S ⇒aSb⇒aaSbb⇒aaabbb
It is easy to prove that the language generated by this grammar is , L (G) = {aibi | i ≥ 1}
By using the first production, it generates the string ab (for i =1).
To generate any other string, it needs to start with the production S→aSb and then the non-
terminal S in the RHS can be replaced either by ab (in which we get the string aabb) or the same
production S→aSb can be used one or more times. Every time it adds an 'a' to the left and a 'b' to
the right of S, thus giving the sentential form aiSbi, i ≥1. When the non-terminal is replaced by
ab (which is then only possibility for generating a terminal string) we get a terminal string of the
form aibi,i≥ 1. There is no general rule for finding a grammar for a given language. For many
languages we can devise grammars and there are many languages for which we cannot find any
grammar.
Example: Find a grammar for the language L= {an b n+1 | n ≥ 1}
It is possible to find a grammar for L by modifying the previous grammar since we need to
generate an extra b at the end of the string an bn , n ≥ 1. We can do this by adding a production
S→Bb where the non-terminal B generates ai bi , i ≥ 1 as given in the previous example. Using
the above concept we devise the following grammar for L.
G = (N, Σ, P, S), where N = { S, B }
P = { S→Bb, B→ab, B→aBb }
Example: Grammar G: ({S, A}, {a, b}, S,{S → aAb, aA →aaAb, A→ε } )
Here, S and A are Non-terminal symbols; a and b are Terminal symbols; ε is an empty string; S
is the Start symbol, S ∈ N ; Production P : S → aAb, aA →aaAb, A→ε
Example: Consider the grammar G=({S}, {a,b}, S,P) with P is given by S → aSb, S → Ꜫ .Then
S  aSb  aaSbb  aabb. so we can write S aabb
The string aabb is a sentence in the language generated by G, while aaSbb is a sentential form.
Example: Derive the string aaabbb from G = ({S, A}, {a, b}, S, {S → aAb, aA →aaAb, A→ε } )
Some of the strings that can be derived are:
S →aAb using production S →aAb
S→aaAbb using production aA →aAb
S→aaaAbbb using production aA → aAb
S→aaabbb using production A →ε
Example: If there is a grammar G: V= {S, A, B} T = {a, b} P = {S →AB, A →a, B →b}
Here S produces AB, and we can replace A by a, and B by b. Here, the only accepted string is ab,
i.e., L(G) = {ab}
Example: Suppose we have the grammar G: V={S, A, B} T={a, b} P={S→AB, A→aA|a, B→bB|b}
Find the language generated by this grammar: L(G) = {ab, a2b, ab2, a2b2, ………}
= { am bn | m ≥ 0 and n ≥ 0}
Example: Suppose, L (G) ={am bn | m ≥ 0 and n > 0}. Find the grammar G which produces L (G).
Solution: Since L(G) = {am bn | m ≥ 0 and n > 0}, the set of strings accepted can be rewritten as:
8
L(G) = {b, ab,bb, aab, abb, …….}
Here, the start symbol has to take at least one ‘b’ preceded by any number of ‘a’ including null.
To accept the string set {b, ab, bb, aab, abb, …….}, we have taken the productions:
S →aS , S →B, B → b and B → bB
S →B→ b (Accepted)
S →B→ bB → bb (Accepted)
S →aS →aB→ab (Accepted)
S →aS →aaS →aaB → aab(Accepted)
S →aS →aB→abB→ abb (Accepted)
Thus, we can prove every single string in L(G) is accepted by the language generated by the
production set. Hence the grammar G: ({S, A, B}, {a, b}, S, { S →aS | B , B → b | bB })
Example: Suppose, L (G) = {am bn | m> 0 and n ≥ 0}. We have to find out the grammar G which
produces L(G).
Solution: Since L(G) = {am bn | m> 0 and n ≥ 0}, the set of strings accepted can be rewritten as:
L(G) = {a, aa, ab, aaa, aab ,abb, …….}
Here, the start symbol has to take at least one ‘a’ followed by any number of ‘b’ including null.
To accept the string set {a, aa, ab, aaa, aab, abb, …….}, we have taken the productions:
S → aA, A → aA , A → B, B → bB ,B → λ
S → aA → aB→ aλ→a (Accepted)
S → aA → aaA→ aaB → aaλ→aa (Accepted)
S →aA →aB→abB→ abλ → ab (Accepted)
S → aA → aaA→ aaaA→aaaB → aaaλ→aaa (Accepted)
S → aA → aaA→ aaB→aabB → aabλ→aab (Accepted)
S → aA → aB→ abB→abbB → abbλ→abb (Accepted)
Thus, we can prove every single string in L(G) is accepted by the language generated by the
production set. Hence the grammar G: ({S, A, B}, {a, b}, S, {S →aA, A → aA | B, B →Ꜫ | bB })
Example: Consider the grammar G where V={S,B} ,T={a,b,c} ,S is the start symbol, and P
consists of the following production rules:
S → aBSc
S → abc
Ba → aB
Bb → bb
This grammar defines the language, L(G) = {anbncn|n ≥ 1} where an denotes a string of n
consecutive a's. Thus, the language is the set of strings that consist of 1 or more a's, followed by
the same number of b's, followed by the same number of c's.
Some examples of the derivation of strings in L(G) are:
S==> abc
S ==>aBSc ==> aBabcc ==>aaBbcc==>aabbcc
S==>aBSc==>aBaBScc==>aBaBabccc==>aaBBabccc==>aaBaBbccc==>aaaBBbccc==>
aaaBbbccc==>aaabbbccc
Example: consider the Grammar, G= (V,T,S,P): T={0, 1}; V={S}; P ={S →0S1, S→ ℇ};Then:
S ⇒* 0n1n
L(G) = {0n1n | n ≥ 1}.
9
Example: consider the Grammar and find the language generate by the given grammar
G= (V, T, S, P): T = {a, b}; V = {S,A,B}; S = S. With Productions in P:
1. S → AB
2. A → aA
3. A → ℇ
4. B → bB
5. B → ℇ
Then: S ⇒1 AB ⇒2 aAB ⇒2 aaAB ⇒2 aaaAB ⇒3 aaaB ⇒4 aaabB ⇒4 aaabbB ⇒5 aaabb
L(G) = {ambn | m, n ≥ 0}
Example: consider the Grammar with more than one symbol on the left side of Productions,
G= (V, T, S, P): T = {a}; V = {S, N, Q, R}; S = S. With Productions in P:
1. S → QNQ
2. QN → QR
3. RN → NNR
4. RQ → NNQ
5. N → a
6. Q → ℇ
Then: S ⇒1 QNQ ⇒2 QRQ ⇒4 QNNQ ⇒2 QRNQ ⇒3 QNNRQ ⇒4 QNNNNQ ⇒* aaaa
L(G) = {a(2n) | n ≥ 0}

1.1.3. Automata
An Automata is an abstract model of a digital computer. It has a mechanism for reading input, and can
produce output and finally automaton has control unit which can have finite number of internal states.
Automata is pictorial representations of machines. It is self-operating machines which act according to a
set of predefined actions and do a specific task or accept strings of a specific language. An automata
model can have
1. Language Accepter (Accepting the string by a model)
2. Language Generator (generating the string)
Finite Automaton:
• A finite automaton (FA) consists of a finite set of states and a set of transitions
from state to state that occur on input symbols chosen from an alphabet ∑.
• For each input symbol there is exactly one transition out of each state (possibly
back to the state itself).
• One state, usually denoted q0 is the initial state, in which the automaton starts.
Some states are designated as final or accepting states.
Formally, a finite automaton is denoted by a 5-tuple (Q, ∑, δ, qo, F), where
• Q is a finite set of states.
• ∑ is a finite input alphabet.
• δ is the transition function mapping Q x ∑ to Q i.e., δ (q,a) is a state for each
state q and input symbol a.
• qo ∈ Q is the initial state.
• F ⊆ Q is the set of final states. It is assumed here that there may be more than
one final state.

10
Transition Diagram: A transition diagram is a directed graph associated with an FA in which
the vertices of the graph correspond to the states of the FA. If there is a transition from state q to
state p on input a, then there is an arc labelled a from state q to state p in the transition diagram.
State is denoted by
Transition is denoted by
Initial state is denoted by
Final state is denoted by

Transition Table: A tabular representation in which rows correspond to states, columns


correspond to inputs and entries correspond to next states.
Finite Automata Model:

Block diagram of a finite automaton


The various components are explained as follows:
(i) Input tape:
- The input tape is divided into squares, each square containing a single symbol from the input
alphabet ∑.
- The end squares of the tape contain the end marker ¢ at the left end and the end marker $ at the
right end.
- The absence of end markers indicates that the tape is of infinite length. The left-to-right
sequence of symbols between the two end markers is the input string to be processed.
(ii) Reading head:
- The head examines only one square at a time and can move one square either to the
left or to the right.
- For further analysis, we restrict the movement of the R-head only to the right side.
(iii)Finite control:
- The input to the finite control will usually be the symbol under the R-head, say a, and the
present state of the machine, say q, to give the following outputs:
o A motion of R-head along the tape to the next square (in some a null move, i.e.
the R-head remaining to the same square is permitted)
o The next state of the finite state machine given by δ(q, a).
Acceptance of String by a Finite Automaton:
The FA accepts a string x if the sequence of transitions corresponding to the symbols of x leads
from the start state to an accepting state and the entire string has to be consumed, i.e., a string x is
accepted by a finite automaton M = (Q, ∑, δ, qo, F)
if δ (q0, x) =q for some q ∈ F.
This is basically the acceptability of a string by the final state.

11
Note: A final state is also called an accepting state. Transition function δ and for any two input
strings x and y, δ (q, xy) = δ (δ (q, x), y)

Example: Consider the finite state machine whose transition function δ is given in the form of a
transition table. Here Q = {q0, q1, q2, q3}, ∑={0,1}, F={q0}.Give the entire sequence of states for
the input string 110101.

δ (q0, 110101) = δ(q1,10101)


= δ(q0,0101)
= δ(q2,101)
= δ(q3,01)
= δ(q1,1) = q0
q0 is final state, therefore given string is accepted by finite automata.

Types of finite Automata:


1. Deterministic finite automata
2. Non-deterministic finite automata

Deterministic finite automaton:


Formally, a deterministic finite automaton can be represented by a 5-tuple M= (Q, ∑, δ, qo, F), where
- Q is a finite set of states.
- ∑ is a finite input alphabet.
- δ is the transition function mapping Q x ∑ to Q i.e., δ (q,a) is a state for each state q and input
symbol a.
- qo ∈ Q is the initial state.
- F ⊆ Q is the set of final states. It is assumed here that there may be more than one final state.
Steps to design a DFA:
1. Understand the language for which the DFA has to be designed and write the language
for the set of strings starting with minimum string that are accepted by FA.
2. Draw transition diagram for the minimum length string.
3. Obtain the possible transitions to be made for each state on each input symbol.
4. Draw the transition table.
5. Test DFA with few strings that are accepted and few strings that are rejected by the
given language.
6. Represent DFA with tuples.

12
Examples
1. Design DFA that accepts all strings which starts with ‘1’ over the alphabet {0,1}
Step 1: Understand the language for which the DFA has to be designed and write the
language for the set of strings starting with minimum string that is accepted by FA.
L = {1, 10, 11, 100, 110, 101, 111, .........................................}
Step 2: Draw transition diagram for the minimum length string.

Step 3: Obtain the possible transitions to be made for each state on each input symbol.

Step 4: Draw the transition table.

Step 5: Test DFA with few strings that are accepted & few strings rejected by the given language.
Case i) Let w=1001 ∈ L
δ(q0,1001) = δ(q1,010)
= δ(q1,10) = δ(q1,0) = q1
q1 is final state and the entire string has been consumed i.e., given string is accepted by DFA.
Case ii) Let w=0001 ∉ L
δ(q0,0001) = δ(q2,001)
= δ(q2,10)
= δ(q2,0)
= q2
q2 is not final state and the entire string has been consumed i.e., given string is rejected by DFA.
Step 6: Represent DFA with tuples. DFA, M= (Q, ∑, δ, qo, F) where Q = {q0, q1, q2} , ∑ = { 0,1 }
δ: δ(q0,0)=q2
δ(q0,1)=q1
δ(q1,0)=q1
δ(q1,1)=q1
δ(q2,0)=q2
δ(q2,1)=q2
q0 – initial state
F – final state = { q1}
13
2. Design DFA that accepts all strings which contains ‘00’ as substring over the alphabet {0,1}
Step 1: Understand the language for which the DFA has to be designed and write the
language for the set of strings starting with minimum string that is accepted by FA.
L={00,100,000,001,1100,1000,0100,1001,0001,11000,11100,................}
Step 2: Draw transition diagram for the minimum length string.

Step 3 : Obtain the possible transitions to be made for each state on each input symbol.

Step 4: Draw the transition table.

Input
State
0 1
q0 q1 q0

q1 q2 q0

q2 q2 q2
Step 5: Test DFA with few strings that are accepted and few strings that are rejected by
the given language.
Case i) Let w = 1001 ∈ L
δ(q0,1001) = δ(q0,001)
= δ(q1,01)
= δ(q2,1)
= q2
q2 is final state and the entire string has been consumed i.e., given string is accepted by DFA.
Case ii) Let w=1011 ∉ L
δ(q0,1011) = δ(q0,011) = δ(q1,11) = δ(q0,1)
= q0
q0 is not final state and the entire string has been consumed i.e., given string is rejected by DFA.
Step 6: Represent DFA with tuples. DFA, M= (Q, ∑, δ, qo, F) where Q = {q0, q1, q2} ∑ = { 0,1}
δ: δ(q0,0)=q1
δ(q0,1)=q0
δ(q1,0)=q2
δ(q1,1)=q0
δ(q2,0)=q2
δ(q2,1)=q2
q0 – initial state
F – final state = { q2 }
14
Nondeterministic finite automaton (NDFA/NFA):
A nondeterministic finite automaton is a 5-tuple (Q, ∑, δ, qo, F), where
• Q is a finite nonempty set of states;
• ∑ is a finite nonempty set of inputs;
• δ is the transition function mapping from Q x ∑ into 2Q which is the power set
of Q, the set of all subsets of Q;
• qo ∈ Q is the initial state; and
• F ⊆ Q is the set of final states
Steps to design a NFA:
1. Understand the language for which the NFA has to be designed and write the language
for the set of strings starting with minimum string that is accepted by FA.
2. Draw transition diagram for the minimum length string.
3. Obtain the possible transitions to be made for each state on each input symbol.
4. Draw the transition table.
5. Test NFA with few strings that are accepted and few strings that are rejected by
the given language.
6. Represent NFA with tuples.

Examples:
1. Design NFA that accepts all strings which contains ‘00’ as substring over the alphabet {0,1}
Step 1: Understand the language for which the NFA has to be designed and write the
language for the set of strings starting with minimum string that is accepted by FA
L={00,100,000,001,0100,1100,1000,1001,0001,11000,11100,.............}
Step 2: Draw transition diagram for the minimum length string.

Step 3: Obtain the possible transitions to be made for each state on each input symbol. 0, 1

Step 4: Draw the transition table.


Input
State
0 1
q0 {q0,q1} q0

qq1
1 q2 -

q2 q2 q2

Step 5: Test NFA with few strings that are accepted and few strings that are rejected by
the given language.

15
Case i) Let w=0100 ∈ L
δ(q0,0100) = δ({q0,q1},100)
= δ (q0, 00)
= δ ({q0, q1},0)
= {q0, q1, q2}
q2 is final state and the entire string has been consumed i.e., given string is accepted by NFA.
Case ii) Let w=1011 ∉ L
δ(q0,1011) = δ(q0,011) = δ({q0,q1},11) = δ(q0,1)
= q0
q0 is not final state and the entire string has been consumed i.e., given string is rejected by NFA.
Step 6: Represent NFA with tuples. NFA, M= (Q, ∑, δ, qo, F) where Q = {q0, q1, q2} ∑ = { 0,1 }
δ: δ(q0,0)={q0,q1}
δ(q0,1) = q0
δ(q1,0) = q2
δ(q1,1) = Ø
δ(q2,0) = q2
δ(q2,1) = q2
q0 – initial state
F – final state = { q2 }

2. Design NFA that accepts strings which contains either two consecutive 0’s or two
consecutive 1’s.
Step 1: Understand the language for which the NFA has to be designed and write the
language for the set of strings starting with minimum string that is accepted by FA.
L={00,11,100,001,110,011,111,000,0100,1011,..............}
Step 2: Draw transition diagram for the minimum length string.

Step 3: Obtain the possible transitions to be made for each state on each input symbol.

Step 4: Draw the transition table.

16
Input
State
0 1
q0 {q0,q3} {q0,q1}
q1 - q2

q2 q2 q2
q3 q4 -

q4 q4 q4

Step 5: Test NFA with few strings that are accepted and few strings that are rejected by the given
language.
Case i) Let the input, w = 01001 ∈ L
δ(q0,0) = {q0,q3} δ(q0,01) = δ(δ(q0,0),1) = δ({q0,q3},1) = δ(q0,1) ∪ δ(q3,1) = {q0,q1}
Similarly, we compute δ(q0,010) = {q0,q3},
δ(q0,0100) = {q0,q3,q4} and
δ(q0,01001) = {q0,q1,q4}
final state
After the entire string is consumed, the FA is in the state q4. As q4 is the final state, the string is a
accepted by FA

Case ii) Let w = 010 ∉ L


δ(q0,010) = δ ({q0,q3},10)
= δ({q0,q1},0)
= {q0,q3}
There is no path to the final state after the entire string is consumed. So the string is
rejected by FA.
Step 6: Represent NFA with tuples. NFA, M= (Q, ∑, δ, qo, F) where Q = {q0, q1, q2, q3,q4}
∑ = { 0,1 }
δ: δ(q0,0)={q0,q3}
δ(q0,1)= {q0,q1}
δ(q1,0)= Ø
δ(q1,1)=q2
δ(q2,0)=q2
δ(q2,1)=q2
17
δ(q3,0)=q4
δ(q3,1)= Ø
δ(q4,0)=q4
δ(q4,1)=q4
q0 – initial state
F – final state = { q2,q4 }
Note: The minimal state DFA, accepting all strings over the alphabet {0, 1} where the nth
symbol in every string from the right end is a 1, has 2n states.
Language recognizers:
A language recognizer is a device that accepts valid strings produced in a given language. Finite
state automata are formalized types of language recognizers. The language accepted by Finite
Automata M designated L(M) is the set {x | δ(q0,x) is in F}.
Applications of FA:
• Used in Lexical analysis phase of a compiler to recognize tokens.
• Used in text editors for string matching.
• Software for designing and checking the behavior of digital circuits.
Limitations of FA:
• FA’s will have finite amount of memory.
• The class of languages recognized by FA s is strictly the regular set. There are certain
languages which are non regular i.e. cannot be recognized by any FA.

Differences between NFA and DFA:


S.N NFA DFA
A nondeterministic automaton is a 5-tuple finite A deterministic finite automaton can be
1
represented by a 5-tuple
M= (Q, ∑, δ, qo, F), where δ: Q x ∑ into 2Q. M= (Q, ∑, δ, qo, F), where δ: Q x ∑ to Q.
NFA is the one in which there exists many paths DFA is a FA in which there is only one path for
2
for a specific input from current state to next state. a specific input from current state to next state.
3 NFA is easier to construct. DFA is more difficult to construct.
4 NFA requires less space. DFA requires more space.
Time required for executing an input string is more. Time required for executing an input string is
5
less.

NFA with ε transitions:


An ε -NFA is a tuple (Q, Σ, δ, qo, F) where
• Q is a set of states,
• Σ is the alphabet,
• δ is the transition function that maps each pair consisting of a state and a symbol in Σ ∪ { ε }
to a subset of Q,
• q0 is the initial state,
• F ⊂ Q is the set of final (or accepting) states.

18
Significance of ε-NFA:
It becomes very difficult or many times it seems to be impossible to draw directly NFA or DFA.
Example:

String acceptance by ε –NFA

19
Example: Check whether the string ‘bbb’ is accepted or not for the above automaton.
ε b b b
q0 q2 q4 q2 q4
ε q1

As q4 is the final state, the given string is accepted by the given ε –NFA.

ε –NFA to NFA Conversion:


Step 1: Find the ε-closure for all states in the given ε-NFA.

ε-closure (q) denotes the set of all states p such that there is a path from q to p labelled ε.
Step 2: Find the extended transition function for all states on all input symbols for the given ε-NFA.
δ' (q,a)= ε-closure(δ (δ'(q, ε),a))
Step 3: Draw the transition table or diagram from the extended transition function (NFA)
Step 4: F is the set of final states of NFA, whose ε -closure contains the final state of ε -NFA.
Step 5: To check the equivalence of ε -NFA and NFA, the string accepted by ε -NFA should be
accepted by NFA.

Example: 1. Convert NFA with ε-moves into an equivalent NFA without ε-moves.

Step 1: Find the ε-closure for all states in the given ε-NFA.
ε -CLOSURE (q0) = {q0, q1, q2}
ε -CLOSURE (q1) = {q1, q2}
ε -CLOSURE (q2) = {q2}

20
Step 2: Find the extended transition function for all states on all input symbols for the given ε-NFA.
δ' (q0,0) = ε-closure(δ (δ'(q0, ε),0))
= ε-closure(δ {q0, q1, q2},0)
= ε-closure(δ(q0, 0) U δ (q1,0) Uδ (q2,0))
= ε-closure(q0 U Ø U Ø)
= {q0, q1, q2}
δ' (q0,1) = ε-closure(δ (δ'(q0, ε),1))
= ε-closure(δ {q0,q1, q2},1)
= ε-closure(δ (q0,1) U δ(q1,1) U δ(q2,1))
= ε-closure(Ø U q1 U Ø)
={q1,q2}
δ' (q0,2) = ε-closure(δ (δ'(q0, ε),2))
= ε-closure(δ { q0,q1, q2},2)
= ε-closure(δ (q0,2) U δ (q1,2) Uδ (q2,2))
= ε-closure(q2 U Ø)
={q2}
δ' (q1,0) = ε-closure(δ (δ'(q1, ε),0))
= ε-closure(δ {q1, q2},0)
= ε-closure(δ (q1,0) Uδ (q2,0))
= ε-closure(Ø)
={ Ø }
δ' (q1,1) = ε-closure(δ (δ'(q1, ε),1))
= ε-closure(δ {q1, q2},1)
= ε-closure(δ (q1,1) Uδ (q2,1))
= ε-closure(q1)
={q1, q2 }
δ (q1,2) = ε-closure(δ (δ'(q1, ε),2))
= ε-closure(δ {q1, q2},2)
= ε-closure(δ (q1,2) U δ (q2,2))
= ε-closure(q2)
={q2}
δ (q2,0) = ε-closure(δ (δ'(q2, ε),0))
= ε-closure(δ (q2,2))
= ε-closure(Ø)
={ Ø}
δ (q2,1) = ε-closure(δ (δ'(q2, ε),1))
= ε-closure(δ (q2,1))
= ε-closure(Ø)
={ Ø }
δ (q2,2) = ε-closure(δ (δ'(q2, ε),2))
= ε-closure(δ (q2,2))
= ε-closure(q2)
={ q2}
Step 3: Draw the transition table or diagram from the extended transition function (NFA)
21
Inputs
State
0 1 2
q0 {q0, q1, q2} {q1, q2} q2

q1 Ø {q1, q2} q2

*q2 Ø Ø q2

Step 4: F is the set of final states of NFA, whose ε -closure contains the final state of ε -NFA.

Inputs
State
0 1 2
q0 {q0, q1, q2} {q1,q2} q2

q1 Ø {q1,q2} q2

q2 Ø Ø q2

Step 5: To check the equivalence of ε -NFA and NFA, the string accepted by ε -NFA should be
accepted by NFA.
String acceptance by ε-NFA:
Let w=001
0 0 ε 1 ε
q0 q0 q0 q1 q1 q2

As q2 is the final state, the string is accepted by the given ε-NFA.

String acceptance by NFA:


If w=001
0 0 1
q0 q0 q0 q1
0 0 q1 1 q2
0 q1 0 q2
q2
As q1 and q2 are final states, the string is accepted by the NFA.

NFA to DFA Conversion:


Step 1: First take the starting state of NFA as the starting state of DFA.
Step 2: Apply the inputs on initial state and represent the corresponding states in the transition table.
Step 3: For each newly generated state, apply the inputs and represent the corresponding states in
the transition table.
Step 4: Repeat step 3 until no more new states are generated.

22
Step 5: The states which contain any of the final states of the NFA are the final states of the
equivalent DFA.
Step 6: Represent the transition diagram from the constructed table.
Step7: To check the equivalence of NFA and DFA, the string accepted by NFA should be
accepted by DFA.
Step 8: Write the tuple representation for the obtained DFA.

Note: If the NFA has n states, the resulting DFA may have up to 2n states, an exponentially
larger number, which sometimes makes the construction impractical for large NFAs.
Example:
1. Construct DFA equivalent to the NFA M=({q0,q1},{0,1}, δ,q0,{q1}) where
δ(q0,0) = {q0,q1} δ(q0,1) = {q1} δ(q1,0) = Ø δ(q1,1) = {q0,q1}
Step 1: First take the starting state of NFA as the starting state of DFA

Q/∑ 0 1
[q0]
Step 2: Apply the inputs on initial state and represent the corresponding states in the transition table.

Q/∑ 0 1
[q0] [q0,q1] [q1]
Step 3: For each newly generated state, apply the inputs and represent the corresponding states
in the transition table.
Q/∑ 0 1
[q 0 ] [q 0,q 1] [q 1 ]
[q 0,q1] [q 0,q 1] [q0,q 1]
[q 1 ] Ø [q0,q 1]
Step 4: Stop the procedure as there are no more new states being generated.
Step 5: The states which contain any of the final states of the NFA are the final states of the
equivalent DFA.
q1 is the final state in NFA. q1 is included in the state [q0,q1] and [q1]. So [q0,q1] and [q1] are the
final states of the DFA.

23
Q/∑ 0 1
[q 0] [q0,q 1] [q1]

[q0,q1] [q0,q 1] [q0,q1]

[ q 1] Ø [q0,q1]
Step 6: Represent the transition diagram from the constructed table.

Step 7: To check the equivalence of NFA and DFA, the string accepted by NFA should be
accepted by DFA.
Let w=1110 be the string accepted by NFA.
Acceptability by NFA:

1 q1 0 Ø
1 q1 0 q0
q0 1 q1 1 q0
1 q0 0 q1
1 q1
0 Ø
Acceptability by DFA:
1 1 1 0
δ([q0],1110) = δ([q1],110) [q0] [q1] [q0,q1] [q0,q1] [q0,q1]
= δ([q0,q1],10)
= δ([q0,q1],0)
= [q0,q1] F
Step 8: Write the tuple representation from the obtained DFA.
DFA M' = (Q, ∑, δ, q0, F) where Q = {[q0], [q0,q1], [q1]} , ∑ = {0, 1}
δ - transition function
[q0] - initial state
F = {[q0], [q0,q1]}

Minimization of Finite Automata:


Two states ql and q2 are equivalent (denoted by q1 ≡ q2) if both δ(q1, x) and δ(q2, x) are final
states. or both of them are nonfinal states for all x ∑*.
Two states q1 and q2 are k-equivalent (k ≥ 0) if both δ(q1, x) and δ(q2, x) are final states or
both nonfinal states for all strings x of length k or less. In particular, any two final states are 0-
equivalent and any two nonfinal states are also 0-equivalent.

24
Equivalence between two FSM’s:
Let M and M’ be two FSM’s over ∑ .We construct a comparison table consisting of n+1 columns
where n is the number of input symbols.
Step 1: 1st column consisting of a pair of states of form (q, q’) where q belongs to M and q’
belongs M’.
Step 2: If (q, q’) appears in the same row of 1st column then the corresponding entry in a column
(a belongs to ∑) is (r,r’) where (r,r’) are pair from q and q’ on a.
Step 3: A table is constructed by starting with a pair of initial states q0, q0’ of M and M’. We
complete construction by considering the pairs in 2nd and subsequent columns which are not in
the 1st column.
(i) if we reach a pair (q, q’) such that q is final states of M and q’ is non-final state of M’ i.e.
terminate construction and conclude that M and M’ are not equivalent.
(ii) if construction is terminated when no new element appears in 2nd and subsequent
columns which are not in 1st column. Conclude that M and M’ are equivalent.
Example: Check whether the given two finite automata’s are equivalent or not.

Solution: q1 is initial state of M1 and q4 is initial state of M2 ,make them a pair and place it in 1st
row of the transition table.
Comparison table
Q/∑ c d
(q1,q4) (q1,q4) (q2,q5)
(q2,q5) (q3,q4)
Here q3 is non-final state and q4 is final state.
Therefore, we stop constructing comparison table and conclude that the two given Finite
Automata’s are not equivalent.

25

You might also like