Theory of Computation
Theory of Computation
IMPORTANT DEFINITIONS
UNIT – I
1. Define Deductive proofs.
These are sequence of statements which are derived from any assumption (hypothesis)
or a given initial statement to a conclusion statement.
The proofs are generated using some facts / accepted logics.
Mathematical Induction
Structural Induction
Inductive step: Assume that the given statement is true for nth value and prove
the statement for n = n+1.
This applies for all integer related statement.
Example:
To prove P Q = Q P, we first assume that P Q ≠ Q P.
Now consider an element, x from P that is also in Q.
x ϵ P Q
M (Q, , ,q0 , F)
q 0 Start state
0 1
q0 q1 q2
Start
Final
state
state
A (Q, , ,q0 , F)
where,
Q Finite set of states.
Transition function
There is only one path for an input from current state to next state.
It is a mapping from Q * Q
AA.4 Theory of Computation
Formally cann be defined as
(q 0 ,) q 0
(q0 , a) ((q 0 , ), a)
M = ( Q, , ,q 0 , F)
where,
Q a finite set of states
Subset
13. Differentiate: DFA and NFA
3. It provides only one state transition It may lead to more than one states for
for a given input given input
4. It has only one final state It has more than one final states
6. It has a single path for an input It may have several paths for a single
from a state input from a state. Backtracking is
required.
Important Definitions AA.5
q0 q1 q2
UNIT – II
1. Define Regular Expressions.
Let ∑ be a given alphabet. Then,
(i) , , and a belongs to ∑, are all regular expressions. [primitive Regular
Expressions]
(ii) If r1 and r2 are regular expressions, then r1+r2, r1r2, r1*, (r1) are also regular
expression if and only if it can be derived from the primitive RE by the
finite number of applications of the rules in (ii).
w = xyz
such that
(i) y ≠
(ii) xy n
3. Concatenation
4. Intersection
5. Complementation
6. Transpose / Reversal
7. Kleene star
8. Homomorphism
9. Inverse homomorphism
5. Write a RE for the language accepting the strings which are starting with 1 and
ending with 0, over the set ∑ = {0,1}
L = {10, 100, 110, 1000, 10101, 111000 ….s,}
R = 1(0+1)*0
6. Write a RE to denote a language, L over ∑* where ∑ = {a, b} that the third
character from right end of the string is always a.
L = aab, aba, aaa, abb, babb, aaaa,…
R = (a+b)* a(a+b)(a+b)
7. Construct a RE for the language, L which accepts all the strings with at least 2 b’s
over the alphabets ∑ = {a,b}
L = {bb, abb, bba, bab,bbb,bbaa, ababa,…}
R =(a+b)*b(a+b)*b(a+b)*
8. Construct a RE for the language which consist of exactly 2 b’s over the set,
∑ = {a, b}
L = {bb, abb, baba, bba, aaaabab,….}
R = a*ba*ba*
9. Construct a RE which denotes a language, L over the set , ∑ = {0}, having even
length of string.
R = (00)*
10. Write a RE which denotes a language, L overt the set, ∑ = {1}, having odd length of
strings
AA.8 Theory of Computation
(i) y ≠ (i.e y 1 )
(ii) xy n
(iii) xykz L k 0
Since xy n and y ≠ ,
x= 0n-1
y=0
z = 1n
By pumping lemma, xykz ≥ L for k ≥ 0
When k = 0;
xy0z = xz
0n-1.1n
L [Comparing the power of 0 and 1 with w]
L is not a regular language.
AA.10 Theory of Computation
UNIT – III
1. Define grammars.
A grammar generates a language with the aid of four elements, G=(V,T,P,S) such
as,
o Terminal symbol
o Non terminal symbol
o Start symbol
o Production rules
Terminal refers to the symbols of the alphabet being used.
o There are several types of terminals namely –
Binary alphabet 0 and 1
Uppercase alphabet A, B, … , Z
Lowercase alphabet a, b, … , z
Decimal alphabets 0, 1, 2, … , 9 etc.
o Most commonly used terminals are binary and lowercase types.
The non-terminal symbols are those variables that denote/produce some terminals
in-turn.
o Non-terminals are equivalent to the states of automation.
o They are usually represented by uppercase alphabets like. A, B, … , Z.
The start symbol is a special non-terminal that works similar to the start state of a
finite automation.
o It is represented by an element in variable set.
The production rules are the translation functions/replacement rules of the
variables.
2. What are the types of grammars?
Type 0 grammars / unrestricted grammars
Type 1 grammars / context sensitive grammars
Type 2 grammars / context free grammars
Type 3 grammars / regular grammars
Important Definitions AA.11
S start symbol
| ≠
A language is said to be context sensitive if the production rules are of the form,
A
non-empty
, can be empty
where,
A is a non-terminal symbol
A
AA.12 Theory of Computation
A [i.e., ]
where,
o the right hand side having a single terminal and may or may not be
followed by non terminals
o Union
o Concatenation
o Intersection
o Complementation
o Difference
o Reversal
o Closure
Unrestricted Recursively
Enumerable Grammars
Content-sensitive
Grammars
Content-free
Grammars
Regular
Grammars
Chomsky hierarchy
9. What is CFL?
The language L(G) of a grammar, G is a set of strings derived from the start
symbol.
It is denoted as
L(G) w | w T * and S w
*
G
„*‟ denotes that the grammar, G is applied over S several times.
If the grammar is applied once, it is denoted as S w
G
The language generated from a context - free grammar is called a context - free
language.
10. Define derivations.
Derivations are the set of strings that are derived from the start symbol, after applying
the production rules, a finite number of times.
*
S | T *
G
where T * .
q, q1 states in Q
a input symbol in or
x, x1 stack symbol in
Let the PDA, P = {Q, , , , q0, z0, F}. Then the language of the PDA, P is L(P)
which is accepted by final state is given by,
*
L(P) = { | (q0, , z0 ) (q, , ) }
P
where,
q0 initial state
input string
q Q final state [q F]
stack symbols
Let P be a PDA defined by {Q, , , , q0, z0, F}. The language of the PDA accepted
by empty stack is defined by,
*
N(P) = { | (q0, , z0 ) (q, , ) }
where,
Q Finite set of states
Set of input symbols
Finite set of stack symbols
Transition functions given by
(q, a, x) has at most one transition for any q in Q, a in or , X in
.
If (q, a, x) is non empty for a in , then (q, , x) must be empty.
q0 Start state
z0 Initial stack symbol
F Final state
Important Definitions AA.19
UNIT – IV
Union
Concatenation
Kleene star
Context free language is not closed under
Intersection
Complementation
Reversal
3. Define normal forms of CFG.
Let the grammar G = (V, T, P, S) be a context free grammar. If the production rules in
G satisfy some restrictions, then they are said to be in normal form.
There are two types of normal forms
o Chomsky normal form (CNF)
o Greibach normal form (GNF)
4. What is Greibach Normal Form?
Greibach normal form is named after Shella Greibach who constructed GNF
grammar initially.
The right hand side of every production starts with a terminal, followed by a string
of variables of zero/ more length.
5. What is Chomsky Normal Form?
Every CFG without null productions can be easily converted into its equivalent
CNF.
6. Define Turing machine.
A Turing machine, M is a 7-tuple given by
M = (Q, , , , q0, B, F)
where,
Q Finite set of states
Finite set of inputs symbols on input tape
Finite set of tape symbols [ B] [where B blank symbol]
Transition function given by
(q, a) = (q', b, M) [M movement left, right, no movement]
q0 Initial state [q0 Q]
B Blank symbol representing empty cell [B ]
F Set of final states [F Q]
7. Define Multiple tracks Turing machine.
The input tape of a Turing machine is an infinite single tape divided into individual
cells.
A multiple track Turing machine is a single tape divided into multiple tracks.
Multitrack Turing machine contain multiple tracks (k) each with set of elements
leading to k symbols on the tape.
… …
B a0 a1 a2 … ai … ak B
A Turing machine with a single tape can have any number of heads to provide
simultaneous accesses over the tape.
… a1 a2 a3 b1 b2 b3 c1 c2 … Input
tape
Head 1 Head 2
Head 3
Finite control
The finite control posses two or more tape heads to access the input tape for
performing multiple reads/writes in a simultaneous and independent manner.
M1 movement of H1 (L / R / N)
M2 movement of H2 (L / R / N)
10. Define Multi-tape Turing machine
A multitape TM is finite control with more than one tape for reading/writing
symbols, storing states etc.
The first tape is mostly used to store the input symbols of the string, .
The second and third tapes are normally used to store the states and state-changes.
… … Tape 1
… … Tape 2
… … Tape 3
Head 3 Head 2
Head 1
Finite control
q0 initial state
B blank symbol
The transition function takes on the states tape symbols and head movement.
12. What are the properties of RE languages?
The semi-decidable / RE language are closed under
1. Union
2. Intersection
3. But not under complementation
AA.24 Theory of Computation
UNIT - V
The halting problem is the problem of finding if the program/machine halts or loop
forever.
1 if M halts on input
h(M, )
0 otherwise
where,
M Turing machine
Input string
YES (if L)
∑* M
NO (if L)
1 if p()
Fp ()
0 if p ()
YES (if L)
∑* M
LOOP FOREVER (if L)
1 if p()
Fp ()
undefined if p ()
5. What is Non self Accepting Language?
NSA is a language that
the code for the turning machine M is in language , L(M)
The TM, M does not accept its own encoded code as input.
NSA can be designed as,
NSA = {w {0,1}* | w = e(m) for M is a Turing machine that does not accept the
string w and w is not a valid code of any TM, M}
6. Define Self Accepting Language
The SA is a language that accepts its own encoding scheme.
The language is described as
o The input string, w which is an encoding scheme for a turning machine , M
o The string, w is accepted by the TM.
SA can be defined as,
SA = {w є{0,1}* | w = e(M) for the turning machine, M and w L(M)}
It is a language containing the input string, w which is a code of the turning
machine that accepts its own encoding.
7. What are Solvable / Decidable / Decision Problems?
AA.26 Theory of Computation
Let P be a decision problem over the set of symbols, ∑ then p is solvable or decidable
if the associated language,
DECIDABLE TM
W ∑* YES
M
NO
A decision problem, P is decidable if P halts with either „YES‟ or „NO‟ on every input,
w. A problem is partially decidable / semi decidable if P is recursively enumerable.
The turning machine, M halts with „YES‟ if w is accepted otherwise M loops forever.
A problem that is not decidable / solvable is said to be Undecidable problem
8. Define Post Correspondence Problem.
The input instance of the problem has two lists of non-null strings {α1, α2, ……..αn}
and {β1,β2,………….βn} over an alphabets, Σ. [Σ having at most two symbols].
The task is to find a sequence of integers i1, i2, … ik [ ik for 1 ≤ k ≤ N ] such that
αi, αi2, ……αik = βi1, βi2 = βik
The PCP is a decision problem that whether the above mentioned sequence exists or
not.
9. State Rice’s Theorem
If R is a property of languages that are satisfied by some but not all recursively
enumerable languages, then the decision problem,
PR : Given a TM,M, does L(M) have property, R?
is unsolvable.
Explanation
Consider a language L such that
L = {M | L(M) has some property P}
where,
P is non-trivial of TM,M
Important Definitions AA.27
wєL
YES
M
w L Loops Forever
wєL
YES
M
w L NO
If w L, then M halts with answer, “NO”. This is also called as Turing Decidable
language.
12. Mention the properties of Recursive and RE Languages
1. The Union of two recursively enumerable languages is recursively enumerable.
2. The language L and its complement L are recursively enumerable, then L and I are
recursive.
3. The complement of a recursive language is recursive.
4. The union of two recursive language is recursive.
AA.28 Theory of Computation
Finite
control
Tape of M 0001010000101….
State of M 0000…0BB…
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-tape
Turing machine.
The Tu thus takes up T, w where T is the special purpose Turing machine that passes
the program in the form of binary string, w is the data set that is to be processed by T.
The universal language, Lu is the set of all binary strings , where represents the
ordered pair <T, w> where
T Turing machine
Example: If the language L1 Time (f), then L is tractable and is less complex in
nature
Tractable problems are those that can be solved in polynomial time period.
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‟ refers to the class of problems that can be solved in polynomial time.
Polynomial – time algorithms are efficient ones that can be solved more rapidly.
NP
A Problem P1 is NP-hard if
o the problem is an NP class problem
o For any other problem , P2 in NP, there is a polynomial time reduction of L2 to
L1
21. What is Polynomial Time Reduction?
If L1 and L2 are two languages over the alphabets ∑1 and ∑2 respectively then L1 is
polynomial - time reducible to L2, if there is a function,
q0 0 q2 1 q1
1 b
a
4 5 7
3. For the grammar SA1B, A0A/ε, B0B/1B/ε give left most and right most
derivation of the following string 00101.
The left most derivation for the string 00101 we get,
S A1B
0A1B
00A1B
For the string 00101, the leftmost derivation is given as,
S A1B [Using S A1B]
0A1B [Using A 0A]
00A1B [Using A 0A]
001B [Using A ]
0010B [Using B 0B]
00101B [Using B 1B]
00101 [Using B ]
Thus the string 00101 ϵ L(G).
The right most derivation for the string 00101is given by
S A1B [Using S A1B]
A10B [Using B 0B]
A101B [Using B1B]
A101 [Using B]
0A101 [Using A 0A]
00A101 [Using A0B]
00101 [Using A]
Thus the string 00101 ϵ L(G).
4. Construct CFG to generate,
a b /nε z
n n t
The given grammar generates equal number of a‟s and b‟s. The grammar is given by,
G = {V, J, P, S}
P={S aSb, S ab}
Anna University Solved Question Paper AB.3
V={S}
T={a, b}
S={S}
5. Is it true that deterministic push down automata and non-deterministic push down
automata are equivalent in the sense of language of acceptances? Justify your
answer?
… … Tape 1
… … Tape 2
… … Tape 3
Head 3 Head 2
Head 1
Finite control
Anna University Solved Question Paper AB.5
The problem which can be answered as “yes” are called solvable (or) decidable.
The problem which can answered as “No” are called undecidable problem.
YES
YES
M1 NO
wєΣ*
M3
YES
M2 NO
NO
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.
Thus the union of two recursive languages is also recursive.
PART - B (5 × 16 = 80 Marks)
11. i) Construct the equivalent Griebach normal form for the CFG G = {A1, A2, A3},
{a,G}, {1, A1} when consists at the following.
A1 A2 A3
A2 A3 A1 /b
A3 A1 A2 /a
L = {an bn cn}
Refer problems in 3.7 of UNIT - III
12. a) i) Construct an NFA equivalent to the following regular expression,
((10) + (0 + 1))* 01
Anna University Solved Question Paper AB.7
q3 1 q4 0 q5
Start
q1 q2 1
q12 q12 0 q12 q15
q7 0 q8
q6 q11
q9 1 q10
L = 0 n 2 n Z +
Assume L is a regular we get contradiction. Let n be the number of states in FA and its queting L.
w = 0 n2
|w| = n2> n
Pumping lemma,
w = xyz
Consider
xy2z. |xy2z| = |x| + 2y + |z| > |x| + |y| + |z| as |y| > 0
|xy| n, |y| n
Here |xy2z| strictly lies between n2 and (n+1)2 but is not equal to any
one of them.