unit-1-theory-of-computation-notes
unit-1-theory-of-computation-notes
UNIT I
AUTOMATA FUNDAMENTALS
+ Verifying systems of all types that have a 昀椀nite number of distinct states, such as
communications protocols or protocols for secure exchange information
r Recursive Languages
à Total Turing Machines (TTM) that halt for every input are used to recognize
recursive languages.
2. Computability theory
Computability theory deals primarily with the question of the extent to which a
problem is solvable on a computer. It is closely related to the branch of mathematical
logic called recursion theory.
3. Models of Computation
The computation models that are developed by formal language theory are ,
v) Turing machine
à The computational models and the languages understandable by these models are
tabulated below.
Uncomputable
1. Alphabet
Example:
i. ∑ ={0,1}
ii. ∑ ={a,b,c}
2. String
Example:
3. Length of a string
Example:
i. |01001| = 5
iii. |0315| = 8
4. Power of an alphabet
The power of an alphabet ∑k, is the set of all strings over ∑ with length k.
Examples:
∑ = {0,1}
∑ 2 = {00, 01, 10, 11}
∑ 3 = {000, 001, 010, 011,100,101,110,111}
……………..
∑* = {e, 0,1, 00, 01,10,11, 000, 001, 010, 011,100,101,110,111……………}
= Σ 0 ∪ Σ1 ∪ Σ 2 .......................
= Σ0 ∪ Σ+
∑ + = {0,1, 00, 01,10,11, 000, 001, 010, 011,100,101,110,111……………}
= Σ1 ∪ Σ 2 ∪ Σ 3 .......................
5. Language (L)
Examples:
7. Complement of a Language( L )
Some computer scientists take the extreme view that a formal proof of the
correctness of a program should go hand-in-hand with the writing of the program itself.
We doubt that doing so is productive. Some also say that proof has no place in the
discipline of programming.
+ The slogan “if you are not sure your program is correct, run it and see” is commonly
offered by them.
+ Testing programs is surely essential. However, testing goes only so far, since you
cannot try your program on every input.
➢ Inductive kind
Recursive proofs of a parameterized statement that use the statement itself with
lower values of the parameter.
➢ Deductive kind
à Each step in the proof must follow, by some accepted logical principle, from either
the given facts, or some of the previous statements in the deductive proof, or a
combination of these.
à The hypothesis may be true or false, typically depending on values of its parameters.
Often, the hypothesis consists of several independent statements connected by a
logical AND.
à An example theorem of the form “if H then C” will illustrate these points.
Theorem 1
If x ≥ 4, then 2x ≥ x2.
Proof
The hypothesis H is “x ≥ 4”. This hypothesis has a parameter, x and thus is neither
true nor false. Rather, its truth depends on the value of x.
à The conclusion C is “2x ≥ x2”. This statement also uses parameter x and is true for
certain values of x and not others.
Example:
Perhaps you can see the intuitive argument that tells us the conclusion 2x= x2 will
be true whenever x ≥ 4. We already saw that it is true for x = 4. As x grows larger than 4,
the left side, 2x doubles each time x increases by 1.
Since 1.5625 < 2, each time x increases above 4 the left side 2x grows more than
the right side x2.
Theorem 2
If x is the sum of the squares of four positive integers, then 2x ≥ x2.
Proof
In deductive proof, we go from a hypothesis H to a conclusion C, i.e., if H then C.
Step 1:
x is the sum of the squares of four integers. Let a, b, c, d be four integers.
x = a2 + b2 + c2 + d2
Step 2:
The integers being squared are at least 1.
a ≥ 1; b ≥ 1; c ≥ 1; d ≥ 1.
Step 3:
Since the integers is at least 1, then its squares is also at least 1.
a2 ≥ 1; b2 ≥ 1; c2 ≥1; d2 ≥ 1
Step 4:
From Step 1 and Step 3, we can inter that x is sum of four squares and each
squares is at least 1. x is at least 1+1+1+1 x ≥ 4.
Step 5:
Step 4 is the hypothesis of the previous problem (2x ≥ x2 if x ≥ 4). We can conclude
that,
2x ≥ x2 (or) a2 + b2 + c2 + d2
If the hypothesis does not use familiar terms like integer, multiplication, addition
etc., then we can convert all terms in the hypothesis to their de昀椀nitions.
Theorem 3
A set S is 昀椀nite if there exists an integer n such that S has exactly n elements. |S| = n.
Where,
T - In昀椀nite.
Proof
We can use proof by contradiction. It is a technique where we assume that the
conclusion is false. Then use that assumption together with hypothesis, prove the opposite
of one of the given statements of the hypothesis. So the only possibility that remains is
that the conclusion is true whenever the hypothesis is true.
Now given statement tells us that S U T = |S| + |T| = n+m, n+m is a integer it
follows U is 昀椀nite. But it contradicts the given statement U is in昀椀nite.
1. If - then
à The most common forms of if - then statements are if H then C can be rewritten as
i. H implies C
ii. H only if C
iii. C if H
(a) x ≥ 4, implies 2x = x2
(b) x ≥ 4 only if 2x = x2
(c) 2x = x2 if x ≥ 4
The statements of the form “A if and only if B” or “Aiff B” has two if - then
statements, is “if A then B” and “if B then A”.
Note:
└x┘- Floor of real number x, is the greatest integer equal to or less than x.
┌x┐- Ceiling of real number x, is the least integer equal to or greater than x.
Theorem 4
Proof
┌x┐≤ x.
┌x┐ = x.
Theorem 5
Sin2ɵ¸ + Cos2ɵ = 1.
It does not have any hypothesis. This theorem can be written in if-then is “if ɵ¸ is
an angle, then sin2ɵ + cos2ɵ = 1”.
r Proofs by contradiction
If E and F are two expressions representing sets, the statement E = F means that
two sets represented are same. i.e., every element in the set represented by E is in the set
represented by F and vice versa.
Example:
Union of sets obeys commutative law. Let S and R be sets. Then R U S = S U R. If
E is the expression in R U S and F is the expression S U R, then E = F, an element
x is in E iff x is in F.
Theorem 6
Distributive law of union over intersection. Let R, S, T be sets. Then prove that
R U (S ∩ T) = (R U S) ∩ (R U T)
Proof
1.. If part: if x is in E, x is in F
Statement Justification
Statement Justification
(a) x is in (R U S) ∩ (R U T) Given
(d) x is inR or x is in both S and T (b), (c) and reasoning about unions.
Example:
“if x ≥ 4, then 2x ≥ x2”. Then the contrapositive of this statement is “if not 2x ≥
x2, then not x ≥ 4”. It is otherwise “not a ≥ b” is equal to a < b.
not x ≥ 4 is x<4
3. Another way to prove a statement of the form “if H then C” is to prove the
statement “H and not C implies falsehood”.
Step 1:
State by assuming both the hypothesis H and the negation of the conclusion C.
Step 2:
Compute the proof by showing that something known to be false follows logically
from H and C. This form of proof is called proof by contradiction.
Example:
Jack Sees Jill, who has just come in from outdoors. On observing that she is
completely dry, he knows that it is not raining.
Proof
Assume the negation of conclusion, ie, it is raining, then Jill would be wet. But
she is not wet, so it must not be raining.
Theorem 7
Proof
H = S is 昀椀nite set of U
U is an in昀椀nite set
Conclusion C = “T is infinite”
From the assumption S is 昀椀nite, if T is also 昀椀nite, then U = S U T is also 昀椀nite. But
hypothesis says U is in昀椀nite. Therefore the logical statement is false.
Example:
Theorem 8
Proof
The integer 2 is prime, but 2 is even.
Theorem 9
Proof
a mod b = a a = qb + r
a = 0 x b + a. q = quotient r = remainder.
But b mod a < a, is between 0 - 1. Thus when a < b, b mod a < a mod b, so a mod
b = b mod a is impossible. It is same argument for a > b also.
r P(1)
Condition (a) is called basis and the condition (b) is called inductive step, because
it connects Pn with Pn+1.
à In automata theory, there are several recursively de昀椀ned structures about which we
need to prove statements.
à Like inductions, all recursive de昀椀nitions have a basis case, where one or more
elementary structures are de昀椀ned, and an inductive step, where more complex
structures are de昀椀ned in terms of previously de昀椀ned structures.
Example:
Let us take expressions using the arithmetic operators + and *, with both numbers
and variables allowed as operands.
Basis
Any number or letter (i.e., a variable) is an expression.
Induction
If E and F are expressions, then so are E + F, E*F, and (E).
Example:
Both 2 and x are expressions by the basis. The inductive step tells us x+2, (x + 2)
and 2*(x + 2) are all expressions. Notice how each of these expressions depends on the
previous ones being expressions.
When we have a recursive de昀椀nition, we can prove theorems about it using the
following proof form, which is called structural induction.
Let S(X) be a statement about the structures X that are de昀椀ned by some particular
recursive de昀椀nition.
à For the inductive step, take a. structure X that the recursive de昀椀nition says is
formed from Y 1,Y2,..., Yk. Assume that the statements S(Y1), S(Y2), ….., S(Yk),
and use these to prove S(X).
Our conclusion is that S(X) is true for all X. The following Theorem gives the
facts and proof for trees and expressions.
Theorem 10
Proof
The formal statement S(T) we need to prove by structural induction is: “if T is a
tree, and T has n nodes and e edges, then n = e + 1”.
Basis
The basis case is when T is a single node. Then n = 1 and e = 0, so the relationship
n = e + 1 holds.
Induction
Let T be a tree built by the inductive step of the de昀椀nition, from root node N and k
smaller trees T1 , T2 ,..., Tk . We may assume that the statements S(Ti ) hold for i = 1, 2,...,
k. That is, let Ti have ni nodes and ei edges; then ni = ei + 1.
The nodes of T are node N and all the nodes of the Ti’s. There are thus 1 + n1 + n2
+....+ nk nodes in T. The edges of T are the k edges we added explicitly in the inductive
de昀椀nition step, plus the edges of the Ti’s.
k + 1 + el + e2 + …. + ek ... (1.5)
This expression is exactly 1 more than the expression (1.3) that was given for the
number of edges of T. Thus, T has one more node than it has edges.
Theorem 11
Proof
Formally, we prove the statement S(G) about any expression G that is de昀椀ned by
the recursion example described earlier the numbers of left and right parentheses in G are
the same.
Basis
Induction
There are three rules whereby expression G may have been constructed according
to the inductive step in the de昀椀nition:
r G=E+F
r G=E*F
r G = (E)
We may assume that S(E) and S(F) are true; that is, E has the same number of
left and right parentheses, say n of each, and F likewise has the same number of left and
right parentheses, say m of each. Then we can compute the numbers of left and right
parentheses in G for each of the three cases, as follows:
1. If G = E + F
2. If G = E * F
The count of parentheses for G is again n + m of each, for the same reason as in
case (i).
3. If G = (E)
In each of the three cases, we see that the numbers of left and right parentheses in
G are the same. This observation completes the inductive step and completes the proof.
à These statements tell under what sequences of inputs the automaton gets into each
of the states.
Example:
Let us take the on/off switch, which can be represented as an automaton. The
automaton itself is reproduced as given below.
Push
Start off on
Push
Since on pushing the button switches the state between on and off, and the switch
starts out in the off state, we expect that the following statements will together explain
the operation
1. S1 (n)
2. S2 (n)
We might suppose that S 1 implies S2 and vice-versa, since we know that a number
n cannot be both even and odd. However, what is not always true about an automaton is
that it is in one and only one state. It happens that the automaton is always in exactly one
state, but that fact must be proved as part of the mutual induction.
We give the basis and inductive parts of the proofs of statements S1(n) and S2(n)
below. The proofs depend on several facts about odd and even integers:
Basis
For the basis, we choose n = 0. Since there are two statements, each of which must
be proved in both directions (because S1 and S 2 are each “if-and-only-if” statements),
there are actually four cases to the basis, and four cases to the induction as well.
i. [S1; If]
Since 0 is in fact even, we must show that after 0 pushes, the automaton is in state
off. Since that is the start state, the automaton is indeed in state off after 0 pushes.
The automaton is in state off after 0 pushes, so we must show that 0 is even. But
0 is even by de昀椀nition of “even”, so there is nothing more to prove.
The hypothesis of the “if” part of S2 is that 0 is odd. Since this hypothesis H is
false, any statement of the form “if H then C” is true, which has discussed earlier. Thus,
this part of the basis also holds.
The hypothesis, that the automaton is in state on after 0 pushes, is also false, since
the only way to get to state on is by following an arc labeled Push, which requires that the
button be pushed at least once. Since the hypothesis is false, we can again conclude that
the if-then statement is true.
Input: String
State
Input Tape
Control
0 1 0 1 1
Operation
String Processing (scans the string from left to right, one symbol at a time and
moves from state to state ) using its transition function.
M = (Q, Σ, δ, q0, F)
* ( an alphabet)
1. Transition function
It is a function which guides the automata in string processing. It takes two inputs
(a state, a symbol) and gives one output (state). Transition function can be represented in
three ways. They are,
i. Diagrammatic representation
Nodes and edges are used. Nodes represent the states and edges represent the
moves. The labels of the edges represent the processing symbols. There are two types
of nodes: a) single circled node indicating non-昀椀nal (non-accepting ) state; b) double
circled node indicating 昀椀nal state.
It consists of Rows and columns. Rows indicate state and columns indicate
symbol. The entries of the table indicate the output state. The arrow and star symbols are
used to point out the starting and 昀椀nal states respectively.
Example:
a b
q q q
Fig. 1.2 The transition diagram of FA for the language L={w | w contains ab}
δ:
Q = {q0,q1,q2}
Σ = {a,b}
q0 = q0
F = q2
Table 1.2 The transition table of FA for the language L={w | w contains ab}
Δ a b
→q0 q1 q0
q1 q1 q2
* q q q
δ(q0 , a) = q1 δ(q0 , b) = q0
δ(q1 , a) = q1 δ(q1 , b) = q2
δ(q2 , a) = q2 δ(q2 , b) = q2
1. Deterministic
à If there is exactly one output state in every transition function of an automata, then
the automata is called Deterministic 昀椀nite Automata (DFA)
* ( an alphabet)
2. Non-Deterministic
à NFA is the preliminary form of a machine, which can be easily constructed using
the basic constraints of a language.
à Then it can be converted into DFA using subset construction method and 昀椀nally
minimization methods are used to reduce the size of the machine.
à A Non-Deterministic 昀椀nite automaton (NFA) is represented by 5-tuples.
( an alphabet)
3. ε-NFA
à If there is a transition for ε symbol in NFA , then the automata is called ε-NFA.
An ε-Non-Deterministic 昀椀nite automaton (NFA) is represented by 5-tuples.
( an alphabet)
1. L(M)
2. L(DFA)
{w dˆ(q0 , w ) = p ∈ F }
Where,
dˆ(q0 , w ) is an extended transition function that takes a state q0 and a string w and
returns a state p which is in F = Regular language.
3. L(NFA)
à An automata processes the given string and gives Yes/No as the output.
à During string processing, the symbols in the given string are processed one by one,
from left to right according to the moves de昀椀ned by the transition functions of the
automata.
à During string processing, automata selects the transition function whose input
matches with the current state (state and symbol) and performs a move to output
state.
Problem 1.1
δ a b
→q0 q1 q0
q1 q1 q2
* q2 q2 q2
=dˆ(q1 , bb)
= d (q2 , b)
= q2 ∈ F
b b a b b
q0 q0 q0 q1 q2 q2 F
Problem 1.2
q0 0
q1 1 q2
0 0,1
r Design an NFA
r ε-NFA
Problem 1.3
Design an NFA for the following finite languages over the alphabet {a,b}
a. L={ε}
b. L={a}
c. L={b}
d. L={a,b}
e. L={aa,ab}
f. L={aba,abb,aaa}
Solutions:
a. L={ε}
Σ={a,b}
δ : Transition diagram
q0
b. L={a}
Σ={a,b}
δ : Transition diagram
a
q0 q
1
c. L={b}
Σ={a,b}
δ : Transition diagram
b
q0 q1
d. L={a,b}
Σ={a,b}
δ : Transition diagram
a
q0 q1
0
b
q
2
e. L={aa,ab}
Σ={a,b}
δ : Transition diagram
a a
q0 q q2
1
b
q
3
f. L={aba,abb,aaa}
Σ={a,b}
δ : Transition diagram
a a a
q0 q1 q2 q3
b
q4 b
q5
a
q6
Problem 1.4
Design an NFA without ε-Transitions for the following infinite languages over the
alphabet {a,b}.
b. The set of all strings with the substring aba(L={w| w has substring aba}).
c. The set of all strings beginning with bb (L={w| w begins with bb)}).
d. The set of all strings with even number of a’s (L={w| w has even number
of a’s}).
e. The set of all strings with even number of b’s(L={w| w has even number
of b’s }).
f. The set of all strings with odd number of a’s (L={w| w has odd number of
a’s}).
g. The set of all strings with odd number of b’s (L={w| w has odd number of
b’s}).
h. The set of all strings whose third symbol from the right end is b (L={w| w’s
third symbol from the right end is b}).
i. The set of all strings whose third symbol from the left end is b (L={w| w’s
third symbol from the left end is b}).
Solutions:
a. The set of all strings ending in aa.
Σ={a,b}
δ : Transition diagram
a,b
a a
q0 q q2
1
Σ={a,b}
δ : Transition diagram
a,b
Σ={a,b}
δ : Transition diagram
a,b
b b
q0 q q
1 2
Σ={a,b}
δ : Transition diagram
b a b
q q
0 1
a
e. The set of all strings with even number of b’s.
NFA M=(Q, Σ, δ, q0, {q0})
Σ={a,b}
δ : Transition diagram
a b a
q0 q
1
b
f. The set of all strings with odd number of a’s.
δ : Transition diagram
b b
a
q q
0 1
a
g. The set of all strings with odd number of b’s.
Σ={a,b}
δ : Transition diagram
a a
b
q q
0 1
b
h. The set of all strings whose third symbol from the right end is b.
Σ={a,b}
δ : Transition diagram
a,b
b a,b a,b
q0 q1 q2 q3
i. The set of all strings whose third symbol from the left end is b.
Σ={a,b}
δ : Transition diagram
a,b
a,b a,b b
q0 q1 q2 q3
1. Automata for L
If the automata is given for a language Ḹ , then the automata for can be easily
constructed by changing all the non-昀椀nal states to 昀椀nal states and 昀椀nal states to non-昀椀nal
states.
Given:
The FA of L= {w | w consists of 10 as substring}
Where Q={ A, B ,C }
Σ={a,b}
δ : Transition diagram
1 0,1
0
A B C
1 0
Where Q={ A, B ,C }
Σ={a,b}
δ : Transition diagram
0 1 0,1
A C
A B
1 0
2. Automata for L1 L 2
Problem 1.5
Where Q={p, q }
Σ={a,b}
δ1 : Transition diagram
a b a
p q
b
Problem 1.6
Where Q={ r, s }
Σ={a,b}
δ2 : Transition diagram
b b
a
r s
a
Then, M(L1 ∩ L2) = ({pr, ps, qr,qs}, {a,b}, δ, pr, ps)
d ( pr , a) = ( d1 ( p, a), d2 (r , a))
= ( p, s )
d ( pr , b) = ( d1 ( p, b), d2 (r , b))
= ( q, r )
a
pr ps
a
b b b b
a
qr qs
a
Problem 1.7
For the NFA M given in the following table, test whether the strings 01122, 1221
are accepted by M.
δ 0 1 2
→*q0 {q0, q1, q2 } {q1, q2 } {q2 }
*q2 Ф Ф {q2 }
= dˆ({q1 , q2 }, 22)
= dˆ({q }, 2)
2
= q2 ∈ F
There is at least one path from the starting state to 昀椀nal state. Therefore the given
string is accepted.
0 1 1 2 2
q0 q0 q1 q1 q2 q2 ∈ F
0 q1 1
q2 1 q2
0
q2
= dˆ({q2 },1)
=f ∉ F
1 q 2 q2 2 q2 1
q0 1 f∉F
q2 2 q 2 q2 1 f ∉ F
2
There is no even a single path from starting state to 昀椀nal state. Therefore the given
string is not accepted.
Theorem 12
Proof by induction
The “if” part : If L is accepted by some NFA then L is accepted by some DFA. If
D={QD , Σ, δD, {q0},FD} is the DFA constructed from NFA, N={QN , Σ, δN, q0,FN} by the
subset construction ,then L(D) = L(N).
Proof
Observe that each of the d̂ functions returns a set of states from QN, but dˆD
interprets this set as one of the states of QD (which is the power set of QN ), while interprets
this set as a subset of QN.
Basis
Let w = 0 ; that is, w=e. By the basis de昀椀nitions of d̂ for DFA’s and NFA’s, both
dˆD ({q0 }, e ) and dˆN (q0 , e ) are {q 0 }
Induction
Let w = n + 1 , and assume the statement for length n. Break w as w=xa, where
a is the 昀椀nal symbol of w.
Let both these sets of N’s states be {P1, P2,...... Pk} .i.e.
The inductive part of the de昀椀nition of for the NFA’s say that
k
dˆN (q0 , w ) = dN ( pi , a) ... (1.8)
i =1
From (1.7) and (1.9), the inductive part of the de昀椀nition of d̂ for DFA is written as:
When we observe that D and N both accept w if and only if dˆD ({q0 }, w ) or
dˆN (q0 , w ) respectively, contain a state in FN.
We have only to convert a DFA into identical NFA.Put intuitively, if we have the
transition diagram for a DFA, we can also Interpret it as the transition diagram of an NFA,
which happens to have exactly one choice of transition in any situation.
More formally, let D={Q, Σ, δD, q0,F} be a DFA. De昀椀ne N={Q, Σ, δN, q0,F} to be
the equivalent NFA.
It is then easy to show by induction on w , that if dˆD (q0 , w ) = p then dˆN (q0 , w ) = { p}
Method 1
Steps
1. Include the starting state of NFA (q0) in DFA as starting state of DFA.
3. If the output state is new state, include it in DFA and 昀椀nd the transition for
all the symbols from that state.
5. The state which includes 昀椀nal state of NFA is the 昀椀nal state of DFA.
Problem 1.8
0,1
0 1
q0 q q
1 2
δD 0 1 2
Step 1:
Include q0
Step 2:
Find transitions for 0,1 from q0.
Step 3:
Find transitions for 0,1 from new state.
Step 4:
1 0
1 0
Method 2
Steps
2. Copy the 昀椀rst row of NFA table (transition function of start state) to DFA
table.
4. If there is any new state, 昀椀nd the transition function for that new state using
the following formula:
k
dD ({q1 ,..., qk }, a) = dN (qi , a)
i =1
δD 0 1
Procedure
1 0
Σ = {0,1}
q0 = q0
F ={q0,q2}
Problem 1.9
δN a b
q1 q2 q1
q2 q3 q3
* q3 - q2
Procedure
a,b
b b
a a {q0, q1,q2} b {q0, q1,q3}
q0 {q0, q1 }
a,b
{q0,q1,q2,q3}
Problem 1.10
δN 0 1
→p { p,r } {q}
q { r,s } { p}
*r { p,s} {r}
*s { q,r } -
δD 0 1
→p { p,r } { q}
{ q} { r,s } { p}
*{ r,s } { p,q,r,s } { r}
*{ r} { p,s} {r}
*{ p,s} { p,q,r } { q}
0 1
{p,r} {q,r }
p
1
1 1 1
1
0 0
{r,s} {p,r,s} 0 {p,q,r}
q
1 0
1 0 1
{p,s}
0
{r} {p,q,r.s} 1
1
0 0
Problem 1.11
Convert the following NFA to a DFA and informally describe the language it
accepts.
Transition table of given NFA
δN 0 1
→p { p,q } { p}
q { r,s } { t}
r { p,r} {t}
*s - -
*t - -
δD 0 1
→p { p,q } { p}
*{p,t} { p,q } { p}
Problem 1.12
0 1
→p {q,s} {q}
*q {r} {q,r}
r {s} {p}
*s - {p}
1
{p} 0
{q,s}
{q,r}
1
1 0
1 1 1
1
{r}
{s}
0 {p,q,r}
0 0
0
1
{r,s}
[q, {q,r,s}
s] 0
Language of DFA
L(DFA)={w dˆ(q0 , w) is in F}
* w is a string.
ε-Closure
Epsilon closure of a state is the set of all states that are reachable by following the
transition function from the given state through ε edge.
Problem 1.13
δN ε 0 1 2
→q0 q1 q0 Ф Ф
q1 q2 Ф q1 Ф
*q2 Ф Ф Ф q2
Problem 1.14
Design an ε-NFA for the language which consists of strings that has 1’s followed
by 2’s followed by 3’s.
1 2 3
e q e r
p
Q = {p,q,r}
Σ = {1,2,3}
Problem 1.15
Q = {p,q}
Σ = {b}
Problem 1.16
Design an ε-NFA for the language which consists of strings with all a’s followed
by all b’s.
a b
q e
r
Q = {q,r}
Σ = {a,b}
Problem 1.17
For the ε-NFA M given in the following table, test whether the strings aabccand
abba are accepted by M.
δ ε a b c
→p {q} {p} Ф Ф
q {r} Ф {q} Ф
*r Ф Ф Ф {r}
Step 1:
Compute ε-Closure [states that can be reached by traveling along zero or more ε
arrows] for all states .
1. (p)= {p,q,r}
2. w=abba
An ε-NFA can be converted into DFA. The subset construction method (with ‘Lazy
Evaluation’) is used to convert ε-NFA to DFA. In this method the transition functions are
generated only for reachable states.
Theorem
A language L is accepted by some -NFA if and only if L is accepted by some
DFA.
Proof
Thus, the transitions of E and D are the same , but E explicitly states that there are
no transitions out of any state on ε.
2. Only -If part: If the L is accepted by some -NFA then L is accepted by some
DFA.
Let E = {QE, Σ, δE, q0, FE} be an ε -NFA. Apply the modi昀椀ed subset construction
to produce the DFA.
^ We need to show that L(D) = L(E), and we do so by showing that the extended
transition functions of E and D are the same.
* We also know that qD = ECLOSURE (q0 ) , because that is how the start state
of D is de昀椀ned.
* Finally, for a DFA, we know that dˆ( p, e ) = p for any state p, so in particular
dˆD (qD , e ) = ECLOSURE (q0 ) .
r Where, a is the 昀椀nal symbol of w and assume that the statement holds
for x.
* Let both these sets of states be {p1, p2,....pk}. By the de昀椀nition of d̂ for ε-
NFA’s, we compute dˆE (q0 , w) by,
* Thus, dˆD (qD , w) , which is δD({p1, p2,....pk},a) is the same set as dˆE (q0 , w) .
* We have now proved that dˆE (q0 , w) = dˆD (qD , w) and completed the inductive
part.
f. If there is any new state, 昀椀nd the transition function for that new state using
the following formula:
k
dD ({q1 ,..., qk }, a ) = e − closure( dN (qi , a ))
i =1
1. Applications of FA
i. Text Search
2. Limitations of FA
Example:
* L=wwR
* L=WW
* L=WCWR
Analysis
^ Let string1 be considered as s1s2 and string 2 be considered as s3s4 where s1,s2,s3
and s4 are substrings.
^ For all s2 and s3, if s2≠s3, we can easily construct the NFA.
^ In this problem there is no such s2 and s3 where s2=s3. Therefore we can construct
the NFA in one step as follows:
0,1
0 0 1 1
A B C D E
δD 0 1
→ {A} {B} -
{B} {C} -
{C} {C} {C,D}
Note: It is dif昀椀cult to draw the NFA for the following languages wheres2=s3.
^ Set of all strings that begins with 01 and ends with 11 [s2=1]
^ Set of all strings that begins with 01 and ends with 10 [s2=1]
^ Set of all strings that begins with 01 and ends with 01 [s2=01]
^ Set of all strings that begins with 10 and ends with 10 [s2=10]
^ Set of all strings that begins with 00 and ends with 00 [s2=00]
^ Set of all strings that begins with 11 and ends with 11 [s2=00]
For these kinds of problems we can use the intersection property of regular
languages.
Problem 1.18
Design a DFA that accepts set of all strings that begins with 01 and ends with 11.
Step 1:
Design a DFA that accepts set of all strings that begins with 01
0,1
0 1
A B C
Step 2:
Design a DFA that accepts set of all strings that ends with 11.
0,1
1 1
D E F
Step 3:
Intersection between two DFAs (Lazy Evaluation-processing only reachable
nodes)
0
1
0 1 1
0
{AD} {BD} {CD} {CDE} {CDEF}
0
0
1.8.6 PROBLEMS
1. Consider the following ε-NFA. Covert it into DFA
Transition Table of ε-NFA
δN ε a b c
→p Ф {p} {q} {r}
q {p} {q} {r} Ф
*r {q} {r} Ф {p}
Step 1:
Compute ε-Closure [states that can be reached by traveling along zero or more ε
arrows] for all states.
dˆ( p, e )
r ε-Closure (p) = {p}
r ε-Closure (q) = {p,q} dˆ(q, e )
r ε-Closure (r ) = {p,q,r} dˆ(r , e )
Step 2:
Start with ε-closure (p)= {p}
Where, p is the starting state of given ε –NFA.
Step 3:
Find the transition for{p}
dD ({ p}, a ) = e − closure( dN ( p, a ))
= e − closure( p )
= { p} New State
dD ({ p}, b) = e − closure( dN ( p, b))
= e − closure(q )
= { p, q} New State
dD ({ p}, c) = e − closure( dN ( p, c))
= e − closure(r )
= { p , q , r}
Step 4:
Find the transition for {p,q}
dD ({ p, q}, a ) = e − closure( dN ( p, a ) ∪ dN (q, a))
= e − closure( p, q )
= { p, q}
dD ({ p, q}, b) = e − closure( dN ( p, b) ∪ dN (q, b))
= e − closure(q, r )
= { p , q , r}
dD ({ p, q}, c) = e − closure( dN ( p, c) ∪ dN (q, c))
= e − closure(r )
= { p , q , r}
Step 5:
Find the transition for {p,q,r}
dD ({ p, q, r}, a ) = e − closure( dN ( p, a) ∪ dN (q, a) ∪ dN (r , a))
= e − closure( p, q, r )
= { p , q , r}
dD ({ p, q, r}, b) = e − closure( dN ( p, b) ∪ dN (q, b) ∪ dN (r , b))
= e − closure(q, r )
= { p , q , r}
dD ({ p, q, r}, c) = e − closure( dN ( p, c) ∪ dN (q, c) ∪ dN (r , c))
= e − closure( p, r )
= { p , q , r}
Step 6:
No more new states. Stop the process.
δD a b c
→{p} {p} {p,q} {p,q,r}
{p,q} {p,q} {p,q,r} {p,q,r}
*{p,q,r} {p,q,r} {p,q,r} {p,q,r}
c
2. Consider the following ε-NFA. Covert it into DFA
δ ε a b c
→p {q,r} Ф {q} {r}
q Ф {p} {r} {p,q}
*r Ф Ф Ф Ф
Step 1:
Compute ε-Closure [states that can be reached by traveling along zero or more ε
arrows] for all states .
dˆ( p, e )
r ε-Closure (p) = {p,q,r}
r ε-Closure (q) = {q} dˆ(q, e )
r ε-Closure (r ) = {r} dˆ(r , e )
Step 2:
Start with ε-closure (p)= {p,q,r}
Step 3:
Find the transition for {p,q,r}
Step 4:
Find the transition for {q,r}
Step 5:
Find the transition for {r}
Step 6:
No more new states. Stop the process.
δD a b c
a,c
a,c
Ф
δN ε 0 1 2
→ q0 q1 q0 Ф Ф
q1 q2 Ф q1 Ф
*q2 Ф Ф Ф q2
Step 1:
Compute ε-Closure [states that can be reached by traveling along zero or more ε
arrows] for all states .
Step 3:
Find the transition for { q0, q1, q2}
Step 4:
Find the transition for {q1,q2}
Step 5:
Find the transition for {q2}
Step 6:
No more new states. Stop the process.
δD 0 1 2
→*{ q0, q1, q2} { q0, q1, q2} { q1, q2} {q2}
*{q2} Ф Ф {q2}
Σ = {0,1,2}
δN ε a b
→p {r} {q} {p,r}
q Ф {p} Ф
*r {p,q} {r} {p}
Step 1:
Compute ε-Closure [states that can be reached by traveling along zero or more ε
arrows] for all states.
dˆ( p, e )
r ε-Closure (p) = {p,q,r}
Step 3:
Find the transition for { p,q,r}
dD ({ p, q, r}, a) = e − closure ( dN ( p, a) ∪ dN (q, a) ∪ dN (r , a))
= e − closure (q ∪ p ∪ r )
= e − closure ( p, q, r )
= { p , q, r }
δD a b
→*{ p,q,r} { p,q,r} { p,q,r}
REVIEW QUESTIONS
a b
→p {p,q} p
q r r
r s -
*s s s
b.
δ a b
→p {q,s} {q}
* q {r } {q,r }
r {s} {p}
* s ϕ {p}
c.
δ a b
→p {p,q} {p}
q {r,s } {t}
r {p,r} {t}
* s ϕ ϕ
*t ϕ ϕ
2. Consider the following ε- NFA. Compute the ε- Closure of each state and 昀椀nd it’s
equivalent DFA .
a.
δ ε a b c
→p {q,r} - {q} {r}
q - {p} {r} {p,q}
*r - - - {r}
b.
δ ε a b c
→p ϕ {p} {q} {r}
q {p} {q} {r} ϕ
*r {q} {r} ϕ {p}
3. Construct a minimized DFA for the DFA given below.
a.
δ 0 1
→ A B E
B C F
*C D H
D E H
E F I
*F G B
G H B
H I C
*I A E
b.
δ 0 1
→A B A
B A C
C D B
*D D A
E D F
F G E
G F G
H G D
4. Construct (DFA ) an Automata for the following Language
a. D = { w | w has equal number of occurrences of 01 and 10}
b. D ={{ w | w begins with 10 and ends with 10}
c. D ={{ w | w begins with 01 and ends with 01}
δ ε 0 1
→p {r} {q} {p,r}
q Φ {p } Φ
* r {p,q} {r} {p}
a. Compute the ε-closure of each state.
b. List all the possible strings of length 3 or less accepted by the automaton.
c. Convert the automaton to a DFA.
ε a b c
→p - {p} {q} {r}
q {p} {q} {r} -
*r {q} {r} - {p}
7. Let L be a language accepted by a NFA then show that there exists a DFA that
accepts L.
8. Design a NFA that accepts set of all strings that begins with bb and ends with aa.
Convert it into DFA.
9. Construct a minimized DFA for the DFA given below.
δ 0 1
→a b c
b c d
c c d
*d d d
*e e e
*f f e
10. Design a NFA that accepts empty string or string starts and ends with 0. Convert
it into DFA.
11. De昀椀ne NFA. Explain its signi昀椀cance. Convert the given NFA to DFA. Prove that
both NFA and DFA accepts the string 0110.