Unit 2 - Theory of Computation - WWW - Rgpvnotes.in
Unit 2 - Theory of Computation - WWW - Rgpvnotes.in
Unit 2 - Theory of Computation - WWW - Rgpvnotes.in
Tech
Subject Name: Theory of Computation
Subject Code: IT-503
Semester: 5th
Downloaded from www.rgpvnotes.in
Unit II
Syllabus : Regular grammars, regular expressions, regular sets, closure properties of regular grammars,
Arden’s theorem, Myhill-Nerode theorem, pumping lemma for regular languages, Application of
pumping lemma, applications of finite automata, minimization of FSA.
Unit Objective: Obtain minimized DFA and Application of regular expression and conversion from RE to
Finite Automata and Finite Automata to Regular Expression and Proving language are not regular.
Regular Grammar
Grammar:
A grammar G can be formally written as a 4-tuple (N, T, S, P) where
N or VN is a set of variables or non-terminal symbols
T or ∑ is a set of Terminal symbols
S is a special variable called the Start symbol, S ∈ N
P is Production rules for Terminals and Non-terminals. A production rule has the form 𝛼 → 𝛽,
where 𝛼 and 𝛽 are strings on 𝑉𝑁∪Σ and least one symbol of 𝛼 belongs to VN.
Example:
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:
Regular Expressions Regular Set
(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, …………..}
Regular Set:
Any set that represents the value of the Regular Expression is called a Regular Set.
1. Ø* = ε
2. ε* = ε
3. RR* = R*R
4. R*R* = R*
5. (R*)* = R*
6. RR* = R*R
7. (PQ)*P =P(QP)*
8. (a+b)* = (a*b*)* = (a*+b*)* = (a+b*)* = a*(ba*)*
9. R + Ø = Ø + R = R (The identity for union)
10. Rε = εR = R (The identity for concatenation)
11. ØL = LØ = Ø (The annihilator for concatenation)
12. R + R = R (Idempotent law)
13. L (M + N) = LM + LN (Left distributive law)
14. (M + N) L = LM + LN (Right distributive law)
15. ε + RR* = ε + R*R = R*
Arden’s Theorem:
In order to find out a regular expression of a Finite Automaton, we use Arden’s Theorem along with the
properties of regular expressions.
Statement:
Let P and Q be two regular expressions.
If P does not contain null string, then R = Q + RP has a unique solution that is R = QP*
Proof:
R = Q + (Q + RP)P [After putting the value R = Q + RP]
R= Q + QP + RPP
When we put the value of R recursively again and again, we get the following equation:
R = Q + QP + QP2 + QP3…..
R = Q (є + P + P2 + P3 + ….)
R = QP* [As P* represents (є + P + P2 + P3 + ….)]
Hence, proved.
Myhill-Nerode Theorem:
A language L is regular if and only if RL has a finite number of equivalence classes. Moreover, the
number of states is the smallest DFA recognizing L is equal to the number of equivalence classes of RL.
Pumping lemma:
Pumping lemma is tool that can be used to prove that certain languages are not regular. Observe that
for a regular language,
1. The amount of memory that is needed to determine whether or not a given string is the
language is finite and independent of the length of the string, and
2. If the language consists of an infinite number of strings, then this language should contain
infinite subsets having a fairly repetitive structure.
Intuitively, languages that do not follow both point should be non-regular.
This property is called the pumping lemma. If a language does not have this property, then it must be
non-regular. The pumping lemma states that any sufficiently long string in a regular language can be
pumped, i.e., there is a section in that string that can be repeated any number of times, so that the
resulting strings are all in the language.
Theorem:
Let L be a regular language. Then there exists a constant ‘c’ such that for every string w in L:
|w| ≥ c
We can break w into three strings, w = xyz, such that:
1. |y| > 0
2. |xy| ≤ c
3. For all k ≥ 0, the string xykz is also in L.
Protocol specification
Minimization of DFA:
DFA minimization stands for converting a given DFA to its equivalent DFA with minimum number of
states.
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.
Suppose there is a DFA D < Q, Σ, q0, δ, F > which recognizes a language L. Then the minimized DFA D <
Q’, Σ, q0, δ’, F’ > can be constructed for language L as:
Step 1: We will divide Q (set of states) into two sets. One set will contain all final states and other set
will contain non-final states. This partition is called P0.
Step 2: Initialize k = 1
Step 3: Find Pk by partitioning the different sets of Pk-1. In each set of Pk-1, we will take all possible
pair of states. If two states of a set are distinguishable, we will split the sets into different sets in Pk.
Step 4: Stop when Pk = Pk-1 (No change in partition)
Step 5: All states of one set are merged into one. No. of states in minimized DFA will be equal to no. of
sets in Pk.
Example:
Consider the following DFA
Step 1. P0 will have two sets of states. One set will contain q1, q2, q4 which are final states of DFA and
another set will contain remaining states. So P0 = {{q1, q2, q4}, { q0, q3, q5 } }.
Step 2. To calculate P1, we will check whether sets of partition P0 can be partitioned or not:
i) For set {q1, q2, q4}:
δ ( q1, 0 ) = δ ( q2, 0 ) = q2 and δ ( q1, 1 ) = δ ( q2, 1 ) = q5, So q1 and q2 are not distinguishable.
Similarly, δ (q1, 0) = δ (q4, 0) = q2 and δ ( q1, 1 ) = δ ( q4, 1 ) = q5, So q1 and q4 are not distinguishable.
Since, q1 and q2 are not distinguishable and q1 and q4 are also not distinguishable, So q2 and q4 are
not distinguishable. So, { q1, q2, q4 } set will not be partitioned in P1.
ii) For set { q0, q3, q5 } :
δ ( q0, 0 ) = q3 and δ ( q3, 0 ) = q0
δ ( q0, 1) = q1 and δ( q3, 1 ) = q4
Moves of q0 and q3 on input symbol 0 are q3 and q0 respectively which are in same set in partition P0.
Similarly, Moves of q0 and q3 on input symbol 1 are q3 and q0 which are in same set in partition P0.
So, q0 and q3 are not distinguishable.