0% found this document useful (0 votes)
16 views

CC-7-UNIT-4

The document provides an overview of finite-state machines (FSMs), including definitions and classifications of deterministic (DFA) and non-deterministic finite automata (NFA). It explains key concepts such as alphabets, strings, Kleene star, and grammars, along with formal definitions and examples. Additionally, it discusses the conversion from NFA to DFA and DFA minimization using the equivalence theorem.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

CC-7-UNIT-4

The document provides an overview of finite-state machines (FSMs), including definitions and classifications of deterministic (DFA) and non-deterministic finite automata (NFA). It explains key concepts such as alphabets, strings, Kleene star, and grammars, along with formal definitions and examples. Additionally, it discusses the conversion from NFA to DFA and DFA minimization using the equivalence theorem.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

CORE – 7: Discrete Mathematical Structures – Unit- 4

Finite state machine: A finite-state machine (FSM) or finite-state


automaton (FSA, plural: automata), finite automaton, is a mathematical model of
computation. It is an abstract machine that can be in exactly one of a finite number
of states at any given time.

Formal definition of a Finite Automaton


An automaton 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 alphabet of the automaton.
 δ is the transition function.
 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).

Related Terminologies

Alphabet
 Definition − An alphabet is any finite set of symbols.
 Example − ∑ = {a, b, c, d} is an alphabet set where ‘a’, ‘b’, ‘c’, and ‘d’
are symbols.
String
 Definition − A string is a finite sequence of symbols taken from ∑.
 Example − ‘cabcad’ is a valid string on the alphabet set ∑ = {a, b, c, d}
Length of a String
 Definition − It is the number of symbols present in a string. (Denoted by |S|).
 Examples −
 If S = ‘cabcad’, |S|= 6
 If |S|= 0, it is called an empty string (Denoted by λ or ε)

Kleene Star
 Definition − The Kleene star, ∑*, is a unary operator on a set of symbols or
strings, ∑, that gives the infinite set of all possible strings of all possible
lengths over ∑ including λ.
 Representation − ∑* = ∑0 ∪ ∑1 ∪ ∑2 ∪……. where ∑p is the set of all possible
strings of length p.
 Example − If ∑ = {a, b}, ∑* = {λ, a, b, aa, ab, ba, bb,………..}
Kleene Closure / Plus
 Definition − The set ∑+ is the infinite set of all possible strings of all possible
lengths over ∑ excluding λ.
 Representation − ∑+ = ∑1 ∪ ∑2 ∪ ∑3 ∪…….
∑+ = ∑* − { λ }
 Example − If ∑ = { a, b } , ∑+ = { a, b, aa, ab, ba, bb,………..}

Manas Ku Mishra, Asst. Prof. of Comp. Sc., FM (A) College, BLS. Page 1 of 15
Language
 Definition − A language is a subset of ∑* for some alphabet ∑. It can be finite
or infinite.
 Example − If the language takes all possible strings of length 2 over ∑ = {a,
b}, then L = { ab, aa, ba, bb }
Finite Automaton can be classified into two types −
 Deterministic Finite Automaton (DFA)
 Non-deterministic Finite Automaton (NFA)
Deterministic Finite Automaton (DFA): In DFA, for each input symbol, one can
determine the state to which the machine will move. Hence, it is called Deterministic
Automaton. As it has a finite number of states, the machine is called Deterministic
Finite Machine or Deterministic Finite Automaton.
Formal Definition of a DFA
A DFA 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 alphabet.
 δ is the transition function where δ: Q × ∑ → Q
 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).
Graphical Representation of a DFA:
A DFA is represented by digraphs called state diagram.
 The vertices represent the states.
 The arcs labeled with an input alphabet show the transitions.
 The initial state is denoted by an empty single incoming arc.
 The final state is indicated by double circles.

Example Present Next State Next State


Let a deterministic finite automaton be → State for Input 0 for Input 1
 Q = {a, b, c},
 ∑ = {0, 1}, a a b
 q0 = {a}, b c a
 F = {c}, and
Transition function δ is shown by the table − c b c
Its graphical representation would be as follows −
Non-deterministic Finite Automaton (NFA) : In NFA, for a particular input
symbol, the machine can move to any combination of the states in the machine. 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 NFA
An NFA 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 NFA, 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).

Graphical Representation of an NFA: (same as DFA)


An NDFA is represented by digraphs called state diagram.
 The vertices represent the states.
 The arcs labeled with an input alphabet show the transitions.
 The initial state is denoted by an empty single incoming arc.
 The final state is indicated by double circles.

Example Present Next State Next State


Let a non-deterministic finite automaton be → State for Input 0 for Input 1
 Q = {a, b, c}
 ∑ = {0, 1} a a, b b
 q0 = {a} b c a, c
 F = {c}
The transition function δ is shown by the table. c b, c c
Its graphical representation would be as follows −

Difference between DFA and NFA


DFA NFA
DFA stands for Deterministic Finite NFA stands for Nondeterministic Finite
Automata. Automata.
For each symbolic input symbol, there is For each symbolic input symbol, there

Manas Ku Mishra, Asst. Prof. of Comp. Sc., FM (A) College, BLS. Page 3 of 15
Difference between DFA and NFA
DFA NFA
only one state transition (next state) in can be multiple state transitions (next
DFA. states) in NFA.
DFA cannot use Empty String transition. NFA can use Empty String transition.
DFA is more difficult to construct. NFA is easier to construct.
Time needed for executing an input Time needed for executing an input
string is less. string is more.
DFA requires more space. NFA requires less space then DFA.
NFA to DFA Conversion: Let X = (Qx, ∑, δx, q0, Fx) be an NFA which accepts the
language L(X). We have to design an equivalent DFA Y = (Qy, ∑, δy, q0, Fy) such
that L(Y) = L(X). The following procedure converts the NFA to its equivalent DFA −
Algorithm
Input − An NFA
Output − An equivalent DFA
Step 1 − Create state table from the given NFA.
Step 2 − Create a blank state table under possible input alphabets for the
equivalent DFA.
Step 3 − Mark the start state of the DFA by q0 (Same as the NFA).
Step 4 − Find out the combination of States {Q0, Q1,... , Qn} for each possible input
alphabet.
Step 5 − Each time we generate a new DFA state under the input alphabet
columns, we have to apply step 4 again, otherwise go to step 6.
Step 6 − The states which contain any of the final states of the NFA are the final
states of the equivalent DFA.
Example: Let us consider the NFA shown in the figure below. Find its equivalent
DFA.

Manas Ku Mishra, Asst. Prof. of Comp. Sc., FM (A) College, BLS. Page 4 of 15
(State diagram) (Transition Table)
q δ(q,0) δ(q,1)
a {a,b,c,d,e} {d,e}
b {c} {e}
c ∅ {b}
d {e} ∅
e ∅ ∅

Solution:
(Transition Table) (State diagram)
q δ(q,0) δ(q,1)
[a] [a,b,c,d,e] [d,e]
[a,b,c,d,e] [a,b,c,d,e] [b,d,e]
[d,e] [e] ∅
[b,d,e] [c,e] [e]
[e] ∅ ∅
[c, e] ∅ [b]
[b] [c] [e]
[c] ∅ [b]
∅ ∅ ∅ 1 0,1 0

0,1 ∅
0

DFA Minimization using Equivalence Theorem: If X and Y are two states in a


DFA, we can combine these two states into {X, Y} if they are not distinguishable.
Two states are distinguishable, if there is at least one string S, such that one of δ (X,
S) and δ (Y, S) is accepting and another is not accepting. Hence, a DFA is minimal if
and only if all the states are distinguishable.

Algorithm:
Step 1 − All the states Q are divided in two partitions − final states and non-final
states and are denoted by P0. All the states in a partition are 0th equivalent. Take a
counter k and initialize it with 0.
Step 2 − Increment k by 1. For each partition in Pk, divide the states in Pk into two
partitions if they are k-distinguishable. Two states within this partition X and Y are k-
distinguishable if there is an input S such that δ(X, S) and δ(Y, S) are (k-1)-
distinguishable.
Step 3 − If Pk ≠ Pk-1, repeat Step 2, otherwise go to Step 4.
Step 4 − Combine kth equivalent sets and make them the new states of the
t reduced
DFA.

Example: Let us consider the following DFA.


DFA
q δ(q,0) δ(q,1)
a b d
b a c
c e f
d e f
e e f
f f f

As the states c, d and e moves to same state on particular input, the states c, d and
e are equivalent states. Similarly, states a and b are also equivalent. So the
minimized DFA is as follows.

q δ(q,0) δ(q,1)
(a, b) (a, b) (c,d,e)
(c,d,e) (c,d,e) f
f f f

Grammars: A grammar G can be formally written as a 44-tuple


tuple (N, T, P, S) where −

 N or V is a set of variables or non-terminal


non symbols.
 T or ∑ is a set of Terminal symbols.
 P is Production rules for Terminals and Non
Non-terminals.
terminals. A production rule has
the form α → β, where α and β are strings on V ∪ ∑ and atleast
least one symbol of
α belongs to V.
 S is a special variable called the Start symbol, S ∈ N
Example-1: Grammar G1 = ({S, A, B}, {a, b}, S, {S → AB, A → a, B → b})
Here,
 S, A, and B are Non-terminal
terminal symbols;
 a and b are Terminal symbols
 S is the Start symbol, S ∈ N
 Productions, P : S → AB, A → a, B → b
Example-2: Grammar G2 = (({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 → ε
Derivations from a Grammar: Strings may be derived from other strings using the
productions in a grammar. If a grammar G has a production α → β, we can say
that x α y derives x β y in G. This derivation is written as −
x α y ⇒G x β y
Example: Let us consider the grammar −
G2 = ({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)
⇒ aaAbb (using production aA → aaAb)
⇒ aaaAbbb (using production aA → aaAb)
⇒ aaabbb (using production A → ε)
Language Generated by a Grammar: The set of all strings that can be derived
from a grammar is said to be the language generated from that grammar. A
language generated by a grammar G is a subset formally defined by
L(G)={w|w ∈ ∑*, S ⇒G W}
If L(G1) = L(G2), the Grammar G1 is equivalent to the Grammar G2.
Example-1: If there is a grammar
G: N = {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-2: Suppose we have the following grammar −
G: N = {S, A, B} T = {a, b} P = {S → AB, A → aA|a, B → bB|b}
Manas Ku Mishra, Asst. Prof. of Comp. Sc., FM (A) College, BLS. Page 7 of 15
The language generated by this grammar −
L(G) = {ab, a2b, ab2, a2b2, ………}
= {am bn | m ≥ 1 and n ≥ 1}
Construction of a Grammar Generating a Language: We’ll consider some
languages and convert it into a grammar G which produces those languages.

Example-1: Suppose, L (G) = {am bn | m ≥ 0 and n > 0}. 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) = {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, 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-2: Suppose, L (G) = {am bn | m > 0 and n ≥ 0}. 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)

Manas Ku Mishra, Asst. Prof. of Comp. Sc., FM (A) College, BLS. Page 8 of 15
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 })
Chomsky Classification of Grammars: According to Noam Chomosky, 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
Grammar Accepted Language Accepted Automaton
Type
Recursively enumerable
Type 0 Unrestricted grammar Turing Machine
language
Context-sensitive Context-sensitive Linear-bounded
Type 1
grammar language automaton
Context-free
Type 2 Context-free language Pushdown automaton
grammar
Finite state
Type 3 Regular grammar Regular language
automaton
The following figure shows the scope of each type of grammar –

Type - 3 Grammar: Type-3 grammars generate regular languages. Type-3


grammars must have a single non-terminal on the left-hand side and a right-hand
side consisting of a single terminal or single terminal followed by a single non-
terminal. The productions must be in the form X → a or X → aY
where X, Y ∈ N (Non terminal) and a ∈ T (Terminal)
The rule S → ε is allowed if S does not appear on the right side of any rule.

Manas Ku Mishra, Asst. Prof. of Comp. Sc., FM (A) College, BLS. Page 9 of 15
Example
X → a | aY | ε
Y→b

Type - 2 Grammar: Type-2 grammars generate context-free languages.


The productions must be in the form A → γ
where A ∈ N (Non terminal)
and γ ∈ (T ∪ N)* (String of terminals and non-terminals).
These languages generated by these grammars are recognized by a non-
deterministic pushdown automaton.
Example: S → Xa, X → a | aX | abc | ε

Type - 1 Grammar: Type-1 grammars generate context-sensitive languages. The


productions must be in the form α A β → α γ β
where A ∈ N (Non-terminal)
and α, β, γ ∈ (T ∪ N)* (Strings of terminals and non-terminals)
The strings α and β may be empty, but γ must be non-empty.
The rule S → ε is allowed if S does not appear on the right side of any rule. The
languages generated by these grammars are recognized by a linear bounded
automaton.
Example: AB → AbBc, A → bcA, B → b

Type - 0 Grammar: Type-0 grammars generate recursively enumerable languages.


The productions have no restrictions. They are any phase structure grammar
including all formal grammars. They generate the languages that are recognized by
a Turing machine.
The productions can be in the form of α → β where α is a string of terminals and
nonterminals with at least one non-terminal and α cannot be null. β is a string of
terminals and non-terminals.
Example: S → ACaB, Bc → acB, CB → DB, aD → Db

Regular Expressions: A Regular Expression can be recursively defined as follows:


1. ε is a Regular Expression indicates the language containing an empty
string. (L (ε) = {ε})
2. φ is a Regular Expression denoting an empty language. (L (φ) = { })
3. a in ∑ is a Regular Expression where L = {a}
4. If X is a Regular Expression denoting the language L(X) and Y is a Regular
Expression denoting the language L(Y), then
 X + Y is a Regular Expression corresponding to the language L(X) ∪
L(Y) where L(X+Y) = L(X) ∪ L(Y).

Manas Ku Mishra, Asst. Prof. of Comp. Sc., FM (A) College, BLS. Page 10 of 15
 X . Y is a Regular Expression corresponding to the language L(X) .
L(Y) where L(X.Y) = L(X) . L(Y)
 R* is a Regular Expression corresponding to the
language L(R*)where L(R*) = (L(R))*
If we apply any of the rules several times from 1 to 4, they are Regular Expressions.
Examples of some Regular Expressions
Regular Regular Set
Expressions
(0 + 10*) L = { 0, 1, 10, 100, 1000, 10000, … }
(0*10*) L = {1, 01, 10, 010, 0010, …}
(0 + ε)(1 + ε) L = {ε, 0, 1, 01}
(a+b)* Set of strings of a’s and b’s of any length including the null string.
So L = { ε, a, b, aa , ab , bb , ba, aaa…….}
(a+b)*abb Set of strings of a’s and b’s ending with the string abb. So L =
{abb, aabb, babb, aaabb, ababb, …………..}
(11)* Set consisting of even number of 1’s including empty string, So L=
{ε, 11, 1111, 111111, ……….}
(aa)*(bb)*b Set of strings consisting of even number of a’s followed by odd
number of b’s , so L = {b, aab, aabbb, aabbbbb, aaaab, aaaabbb,
…………..}
(aa + ab + ba + String of a’s and b’s of even length can be obtained by
bb)* concatenating any combination of the strings aa, ab, ba and bb
including null, so L = {aa, ab, ba, bb, aaab, aaba, …………..}

Regular Sets: Any set that represents the value of the Regular Expression is called
a Regular Set.
Identities Related to Regular Expressions: Given P, Q, R, L as regular
expressions, the following identities hold −
 ∅* = ε
 ε* = ε
 RR* = R*R
 R*R* = R*
 (R*)* = R*
 (PQ)*P =P(QP)*
 (a+b)* = (a*b*)* = (a*+b*)* = (a+b*)* = a*(ba*)*
 R + ∅ = ∅ + R = R (The identity for union)
 R ε = ε R = R (The identity for concatenation)
 ∅L=L∅=∅

Manas Ku Mishra, Asst. Prof. of Comp. Sc., FM (A) College, BLS. Page 11 of 15
 R + R = R (Idempotent law)
 L (M + N) = LM + LN (Left distributive law)
 (M + N) L = ML + NL (Right distributive law)
 ε + RR* = ε + R*R = R*

Construction of FA from an RE:

Case 1 − For a regular expression ‘a’, we


can construct the FA as shown in the figure.

Case 2 − For a regular expression


‘ab’, we can construct the FA as
shown in the figure.

Case 3 − For a regular expression (a+b),


we can construct the FA as shown in the
figure.

Case 4 − For a regular expression


(a+b)*, we can construct the FA as
shown in the figure.

Method
Step 1 Construct an NFA with Null moves from the given regular expression.
Step 2 Remove Null transition from the NFA and convert it into its equivalent DFA.
Problem: Convert the RE, 1 (0 + 1)* 0 into its equivalent DFA.
Solution: We will concatenate three expressions "1", "(0 + 1)*" and "0"

Manas Ku Mishra, Asst. Prof. of Comp. Sc., FM (A) College, BLS. Page 12 of 15
Finite Automata with Null Moves (NFA-ε):
(NFA A Finite Automaton with null moves
(FA-ε)
ε) does transit not only after giving input from the alphabet set but also without
any input symbol. This transition without input is called a null move.
An NFA-εε is represented formally by a 5-tuple (Q, ∑, δ, q0, F), consisting of

 Q − a finite set of states


 ∑ − a finite set of input
symbols
 δ − a transition function δ
: Q × (∑ ∪ {ε}) → 2Q

 q0 − an initial state q0 ∈ Q
 F − a set of final state/states of Q (F
(F⊆Q).
The above (FA-ε) accepts a string set − {0, 1, 01}
Removal of Null Moves from Finite Automata
Automata: If in an NFA, there is ϵ-move
between vertex X to vertex Y, we can remove it using the following steps −
 Find all the outgoing edges from Y.
 Copy all these edges starting from X without changing the edge labels.
 If X is an initial state, make Y also an initial state.
 If Y is a final state, make X also a final state.

Problem: Convert the given


NFA-ε to NFA without Null
move.

Solution
Step 1 −
Here the ε transition is between q1 and qf, so let q1 is X and qf is Y.
Y
Here the outgoing edges from qf is to qf for inputs 0 and 1.
Step 2 −
Now we will Copy all these
edges from q1 without
changing the edges from
qf and get the FA as shown
in the figure.

Step 3 −
Here q1 is an initial state, so
we make qf also an initial
state.
So the FA becomes −

Step 4 −
Here qf is a final state, so we
make q1 also a final state.
So the FA becomes −
Pumping Lemma for Regular Language:
Theorem: Let L be a regular language. Then there exists a constant ‘n’ such that for
every string w in L, |w| ≥ n
We can break w into three strings, w = xyz, such that −
 |y| ≥ 1
 |xy| ≤ n
For all k ≥ 0, the string xykz is also in L.
Applications of Pumping Lemma: Pumping Lemma is to be applied to show
that certain languages are not regular. It should never be used to show a language
is regular.
 If L is regular, it satisfies Pumping Lemma.
 If L does not satisfy Pumping Lemma, it is non-regular.
Method to prove that a language L is not regular:
 At first, we have to assume that L is regular.
 So, the pumping lemma should hold for L.
 Use the pumping lemma to obtain a contradiction −
 Select w such that |w| ≥ n
 Select y such that |y| ≥ 1
 Select x such that |xy| ≤ n
 Assign the remaining string to z.
 Select k such that the resulting string is not in L.
Hence L is not regular.
Problem: Prove that L = {aibi | i ≥ 0} is not regular.
Solution −
 At first, we assume that L is regular.
 Let w = anbn. Thus |w| = 2n ≥ n.
 By pumping lemma, let w = xyz, where |xy| ≤ n.
 Let x = ap, y = aq, and z = bn, where p + q = n, p ≠ 0, q ≠ 0. Thus |y| ≠ 0.
 Let k = 2. Then xy2z = apa2qbn.
 Number of a = (p + 2q) = (p + q) + q = n + q
 Hence, xy2z = an+q bn. Since q ≠ 0, xy2z is not of the form anbn.
 Thus, xy2z is not in L. Hence L is not regular.

Manas Ku Mishra, Asst. Prof. of Comp. Sc., FM (A) College, BLS. Page 15 of 15

You might also like