FLAT Notes
FLAT Notes
AUTOMATA FUNDAMENTALS
+ Verifying systems of all types that have a finite 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.
1.6 Theory of Computation
+ 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.
Automata Fundamentals 1.7
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.
1.8 Theory of Computation
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 definitions.
Theorem 3
A set S is finite if there exists an integer n such that S has exactly n elements. |S| = n.
Where,
T - Infinite.
Automata Fundamentals 1.9
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 finite. But it contradicts the given statement U is infinite.
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”.
Automata Fundamentals 1.11
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 finite set of U
U is an infinite set
Conclusion C = “T is infinite”
From the assumption S is finite, if T is also finite, then U = S U T is also finite. But
hypothesis says U is infinite. 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.
Automata Fundamentals 1.15
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 defined structures about which we
need to prove statements.
à Like inductions, all recursive definitions have a basis case, where one or more
elementary structures are defined, and an inductive step, where more complex
structures are defined in terms of previously defined structures.
Example:
Let us take expressions using the arithmetic operators + and *, with both numbers
and variables allowed as operands.
1.16 Theory of Computation
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 definition, 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 defined by some particular
recursive definition.
à For the inductive step, take a. structure X that the recursive definition 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.
Automata Fundamentals 1.17
Induction
Let T be a tree built by the inductive step of the definition, 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
definition 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 defined 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 definition:
1.18 Theory of Computation
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.
Automata Fundamentals 1.19
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:
1.20 Theory of Computation
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 definition 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
Automata Fundamentals 1.21
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,
1.22 Theory of Computation
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-final (non-accepting ) state; b) double
circled node indicating final 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 final 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
Automata Fundamentals 1.23
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 finite 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 finally
minimization methods are used to reduce the size of the machine.
à A Non-Deterministic finite 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 finite 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 defined 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.
1.26 Theory of Computation
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
Automata Fundamentals 1.27
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}
1.28 Theory of Computation
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
Automata Fundamentals 1.29
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}
1.30 Theory of Computation
δ : 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}).
Automata Fundamentals 1.31
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}
1.32 Theory of Computation
δ : 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}
1.34 Theory of Computation
δ : 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-final states to final states and final states to non-final
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
Automata Fundamentals 1.35
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}
1.36 Theory of Computation
δ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 }
Automata Fundamentals 1.37
= dˆ({q1 , q2 }, 22)
= dˆ({q }, 2)
2
= q2 ∈ F
There is at least one path from the starting state to final 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 final state. Therefore the given
string is not accepted.
1.38 Theory of Computation
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 definitions 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 final symbol of w.
Let both these sets of N’s states be {P1, P2,...... Pk} .i.e.
The inductive part of the definition of for the NFA’s say that
Automata Fundamentals 1.39
k
dˆN (q0 , w ) = dN ( pi , a) ... (1.8)
i =1
From (1.7) and (1.9), the inductive part of the definition 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. Define 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 find the transition for
all the symbols from that state.
5. The state which includes final state of NFA is the final 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
1.42 Theory of Computation
Method 2
Steps
2. Copy the first row of NFA table (transition function of start state) to DFA
table.
4. If there is any new state, find 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}
Automata Fundamentals 1.45
*{ 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
1.46 Theory of Computation
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}
1.48 Theory of Computation
* 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}
1.50 Theory of Computation
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}
Automata Fundamentals 1.51
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 modified 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 defined.
* 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 final symbol of w and assume that the statement holds
for x.
* Let both these sets of states be {p1, p2,....pk}. By the definition of d̂ for ε-
NFA’s, we compute dˆE (q0 , w) by,
1.54 Theory of Computation
* 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, find 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 difficult 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]
Automata Fundamentals 1.57
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.58 Theory of Computation
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}
Automata Fundamentals 1.59
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}
1.60 Theory of Computation
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 }
1.66 Theory of Computation
δD a b
→*{ p,q,r} { p,q,r} { p,q,r}
Automata Fundamentals 1.67
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 find it’s
equivalent DFA .
a.
δ ε a b c
→p {q,r} - {q} {r}
q - {p} {r} {p,q}
*r - - - {r}
1.68 Theory of Computation
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}
Automata Fundamentals 1.69
δ ε 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
1.70 Theory of Computation
10. Design a NFA that accepts empty string or string starts and ends with 0. Convert
it into DFA.
11. Define NFA. Explain its significance. Convert the given NFA to DFA. Prove that
both NFA and DFA accepts the string 0110.
UNIT IV
PROPERTIES OF CONTEXT FREE
LANGUAGES
UNIT V
UNDECIDABILITY
UNIT - 5
UNDECIDABILITY
Non Recursive Enumerable (RE) Language – Undecidable Problem with RE –
Undecidable Problems about TM – Post‘s Correspondence Problem, The Class P
and NP
RECURSIVE AND RECURSIVELY ENUMERABLE LANGUAGES
Recursively Enumerable Language
wєL
YES
M
wL Loops Forever
Recursive Language
A language is said to be recursive if there exists of Turing machine, M that accepts
every string, w L and rejects those strings that are not in L.
If the input is accepted, M halts with the answer,” YES”
wєL
YES
M
wL NO
Proof:
Let L1 and L2 be two recursively enumerable languages accepted by the Turing
machines M1 and M2.
If a string wL1 then M1 returns “YES”, accepting the input string: Else loops
forever. Similarly if a string w L2 then M2 returns “YES”, else loops forever.
RE
YES
M1
YES
wєΣ* M3
RE
M2 YES
RE
Here the output of M1 and M2 are written on the input tape of M3. The turning
machine, M3 returns “YES”, if at least one of the outputs of M1 and M2 is “YES”. The M3
decides on L1UL2 that halts with the answer, “YES” if w L1 or w L2 . Else M3 loops
forever if both M1 and M2 loop forever.
Proof
Let L and L be two recursively enumerable languages accepted by the Turing
machines M1 and M2. If a string, w L, it is accepted by M1 and M1 halts with answer
“YES”. Else M1 enters into infinite loop.
w L1 YES
M1
wєΣ* YES
M3
M2
w L YES
From the above design of TM, if w L, if w L, then M1 accepts w and halts with
“YES”.
Since M1 and M2 are accepting the complements of each other, one of them is
guaranteed to halt for every input, wєΣ*.
Hence M3 is a Turing machine that halts for all strings.
Thus if the language and its complement are recursively enumerable, then they are
recursive.
Property - 3
The complement of a recursive language is recursive.
Proof
Let L be a recursive language accepted by the turning machine, M 1.
Let L be a recursive language accepted by the Turing machine M2.
The construction of M1 and M2 are given as,
L
w L YES NO
M1 M2
w L NO YES
R R
Let w L, then M1 accepts w and halts with “YES”.
Property – 4
The union of two recursive language is recursive.
Proof:-
Let L1 and L2 be two recursive languages that are accepted by the Turing machines M1
and M2, given by
L(M1) = L1
L(M2) = L2
Let M3 be the Turing machine constructed by the union of M1 and M2. M3 is
constructed as follows.
YES
YE
M1 NO
wєΣ*
M3
YES
M2 NO
NO
The Turing machine M3 first simulates M1 with the input string, w.
If w L1 , then M1 accepts and thus M3 also accepts since L(M3) = L(M1) u L(M2).
If M1 rejects string w
L1 , then M3 simulates M2. M3 halts with “YES” if M2
accepts „w‟, else returns “NO”.
Hence M3, M2, M1 halt with either YES or NO on all possible inputs.
Property – 5
The intersection of two recursive language is recursive.
Proof:-
Let L1 and L2 be two recursive languages accepted by M1 and M2 where
L(M1) = L1
L(M2) = L2
Let M3 be the Turing machine that is constructed by the intersection of M1 and M2, M3
is constructed as follows.
NO
NO
wєΣ*
M1
YES
YES
YES
M2
NO
If w L1 , then M1 halts along with M3 with answer “NO”, since L(M3)=L(M1)
L(M2). If then M1 accepts with the answer “YES” and M3 simulates M2.
If M2 accepts the string, then the answer of M2 and M3 are “YES” and halts. Else, M2
and M3 halts with answer “NO”.
Thus, the intersection of two recursive languages is recursive.
Property – 6
Intersection of two recursively enumerable languages is recursively enumerable.
Proof:-
Let L1 and L2 be two recursively enumerable languages accepted by the Turing
machine M1 and M2.
If a string w L1 then M1 returns “YES” accepting the input. Else will not halt after
rejecting w L1 .
Similarly if a string, w L2 , then M2 returns “YES” else rejects „w‟ and loop forever.
M1
wЄ∑* YES
YES
M3
YES Loop Forever
M2
Rejects & Never Halts
w L2
Here the output of M1 and M2 are written the input tape of M3. The machine, M3
returns “YES” if both the outputs of M1 and M2 is “YES”.
Thus M3 decides on L1 L2 that halts if and only if w L1 and w L2 . Else M3
loops forever along with M1 or M2 or both
Hence the intersection of two recursively enumerable languages is recursively
enumerable.
Theorem
Halting problem of Turing machine is unsolvable / undecidable.
Proof
The theorem is proved by the method of proof by contradiction.
Let us assume that Turing machine is solvable / decidable.
Construction of H1
M Halting HALT
machine H1 LOOP FOREVER
Consider, a string describing M and input string, for M.
Let H1 generates “halt” if H1 determines that the turing machine, M stops after
accepting the input, .
Otherwise H1 loops forever when, M doesn‟t stops on processing .
Construction of H2
M Halting HALT
machine H2 LOOP
Construction of H3
M HALT LOOP
H2 H3
LOOP HALT
H3
H3
Undecidable problem
A problem, P is said to be undecidable if there is a Turing machine, TM that doesn‟t
decides P.
The tape head never moves to the left on the first tape.
No blank symbol (B) on the first tape is erased or modified.
For all L, where there exists a transition rule, i on tape 1 with contents
1 # 2 # 3 # ... # n # # (for n 0)
Theorem
A language L ∑* is recursively enumerable if and only if L can be enumerated by
some TM.
Proof
Let M1 be a Turing machine that enumerates L.
And let M2 accepts L. M2 can be constructed as a k-tape Turing machine [k(M2) >
k(M1)].
HALTS HALTS
∑* M1 M2
(L) ( L)
A PCP consists of two lists of string over some alphabet Σ; the two lists must be of equal length.
Generally A=w1,w2, w3, …….wk and B= x1, x2 ,x3, ……xk for some integer k. For each i , the
pair (wi , xi ) is said to be a corresponding pair.
We say this instances of PCP has a solution, if there is a sequence of one or more integers
i1, i2,……., im that, when interpreted as indexes for strings in the A and B lists, yield the same
string.
wi1 wi2 ……. wim = xi1 xi2 ……. xim . We say the sequence i1, i2,……., im is a solution to this
instance of PCP
EXAMPLE
1. For Σ = {a, b} with A = {a, aba3, ab} and B = {a3, ab, b}, Does the PCP with A and B
have a solution?
Solution:
The sequence obtained from A and B = (2, 1, 1, 3) as,
A2 A1 A1 A3
aba3 a a ab
B2 B1 B1 B3
ab a3 a3 b
2. Let Σ = {0, 1}. Let A and B be the lists of three strings defined as
A B
I wi xi
1 1 111
2 10111 10
3 10 0
Solution:
Consider the sequence (2, 1, 1, 3)
A2A1A1A3 => w2w1w1w3 = 101111110
B2B1B1B3 => X2X1X1X3 = 101111110
For computing another function, other appropriate Turing machine is used. To do so, the
machine has to be re-written accordingly.
Hence Turing proposed “Stored Program Computer” concept in 1936 that executes the
program/instructions using the inputs, stored in the memory.
Concept of UTM
The universal Turing machine, Tu takes over the program and the input set to process
the program.
The program and the inputs are encoded and stored on different tapes of a multi-tapeTuring machine.
The Tu thus takes up T, w where T is the special purpose Turing machine that passesthe
program in the form of binary string, w is the data set that is to be processed by T.
Finite
control
Tape of M 0001010000101….
State of M 0000…0BB…
Input to the Tu
The universal Turing machine, Tu is always provided with the code for Transitions,
e(T) and code for input, e(w) as
TM e(T)e(w)
Construction of Tu
As in the figure for universal Turing machine, there are three tapes controlled by a
finite control component through heads for each tape.
Tape -1 Input tape and also serves as output tape. It contain e(T) e(w).
Operation of UTM
Theorm :(Lu is Recursively enumerable )
(To prove this Theorem it is necessary to construct a turning machine that accepts
Lu)
UTM checks the input to verify whether the code for TM=<T,w> is a legitimate
for some TM.
Proof
From the definition and operations of UTM, we know that Lu is recursively
enumerable.
Lu accepts the string w if it is processed by the TM,T. Else, rejects „w‟ and the
machine doesn‟t halts forever.
To prove that Lu is not recursive, the proof can be done by contradiction. Let Lu is
Turing decidable [recursive], and then by definitionacceptable.
Lu (complement of Lu) is Turing
We can show that Lu is Turing acceptable, that leads to Ld to be Turing acceptable.
But we know that Ld is not Turing acceptable.
Integer value, I in binary is the corresponding code for TM, T i. Provide <Ti, wi> to the
algorithm A and accept, w if and only if Ti accepts wi.
This is the algorithm for Ld. Hence Lu is Recursively Enumerable but not recursive.
Tractable problems are those that can be solved in polynomial time period.
Intractable Problems
The languages that cannot be recognized by any Turing machine with reasonable space
and time constraint is called intractable problems.
These problems cannot be solved in finite polynomial time. Even problems with
moderate input size cannot achieve feasible solution
P AND NP PROBLEMS
These refer to how long it takes a program to run. Problems in class P can be solved with
algorithms that run in polynomial time.
An algorithm that finds the smallest integer in an array. One way to do this is by iterating over all
the integers of the array and keeping track of the smallest number you've seen up to that
point. Every time you look at an element, you compare it to the current minimum, and if it's
smaller, you update the minimum.
How long does this take? Let's say there are n elements in the array. For every element the
algorithm has to perform a constant number of operations. Therefore we can say that the
algorithm runs in O(n) time, or that the runtime is a linear function of how many elements are in
the array. So this algorithm runs in linear time.
You can also have algorithms that run in quadratic time (O(n^2)), exponential time (O(2^n)), or
even logarithmic time (O(log n)). Binary search (on a balanced tree) runs in logarithmic time
because the height of the binary search tree is a logarithmic function of the number of elements in
the tree.
If the running time is some polynomial function of the size of the input, for instance if the
algorithm runs in linear time or quadratic time or cubic time, then we say the algorithm runs in
polynomial time and the problem it solves is in class P.
NP
There are a lot of programs that don't (necessarily) run in polynomial time on a regular computer,
but do run in polynomial time on a nondeterministic Turing machine. These programs solve
problems in NP, which stands for nondeterministic polynomial time. A nondeterministic Turing
machine can do everything a regular computer can and more. This means all problems in P are also
in NP.
An equivalent way to define NP is by pointing to the problems that can be verified in polynomial
time. This means there is not necessarily a polynomial-time way to find a solution, but once you
have a solution it only takes polynomial time to verify that it is correct.
P = NP, which means any problem that can be verified in polynomial time can also be solved in
polynomial time and vice versa. If they could prove this, it would revolutionize computer science
because people would be able to construct faster algorithms for a lot of important problems.
NP-hard
Solve a problem by reducing it to a different problem. Reduce Problem B to Problem A if, given
a solution to Problem A, It can easily construct a solution to Problem B. (In this case, "easily"
means "in polynomial time.")
If a problem is NP-hard, this means , reduce any problem in NP to that problem. It can solve
that problem, I can easily solve any problem in NP. If we could solve an NP-hard problem in
polynomial time, this would prove P = NP.
NP-complete
NP-hard, and
in NP.
A technical point: O(n) actually means the algorithm runs in asymptotically linear time, which
means the time complexity approaches a line as n gets very large. Also, O(n) is technically an
upper bound, so if the algorithm ran in sublinear time you could still say it's O(n), even if that's
not the best description of it.
** Note that if the input has many different parameters, like n and k, it might be polynomial in n
and exponential in k