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

TOC AnswerKey

Uploaded by

unknown17112004
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

TOC AnswerKey

Uploaded by

unknown17112004
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

5675154

B.Tech. DEGREE EXAMINATION, DECEMBER 2023

Fifth Semester

Information Technology

THEORY OF COMPUTATION

(2013 – 14 Regulations)

Time: Three hours Maximum: 75 marks

PART A – (10 * 2 = 20 marks)

Answer ALL the questions.

1. Construct a NFA that accepts the set of all strings with an even number of zero’s and an
even number of 1’s.

NFA accepting only odd number of 1’s over an alphabet Σ= {0,1}.

The language it generates is −

L={1,111,01,001,0111,0010,01110,….}

 State o1 on 0 goes to o1 and on 1 goes to state o2.


 State o2 on 0 goes to o2 and on 1 goes to o1.

2. State the differences between Moore and Mealy machines.

Definition A Mealy Machine changes its output A Moore Machine’s output depends only on
on the basis of its present state and the current state. It does not depend on the
current input. current input.

Output Mealy Machine places its output on Moore machine also places its output on the
the transition. transition.
States It has comparatively fewer or the same It has comparatively fewer or the same
states as that of the Moore machine. states as that of the Mealy machine.

Requirement of A Mealy Machine generally requires The states for synthesis required for this
States only a very few states for the process machine are also more.
of synthesis.

3. Identify the language of the given RE i.e. if R = 0*1(0+1)*, L(R) = ?

4. List the regular expression operators and state their order of precedence.
()>*>.>+
 Star (*)
 Concatenation ( .)
 Union (+)
5. For the following grammar, find the leftmost and rightmost derivations for the string,
+*xyxy
E  +EE | *EE |x|y.

6. Write a Context Free Grammar for (011+0)*(01)*.


7. What is a nullable variable? Give an example.
If S can appear on the RHS of a rule, say S → SS, then when there is the rule S → ε, we can
again have long intermediate strings yielding short final strings. Nullable Variables
8. With an example, illustrate “Instantaneous Description” of a Turing Machine?
All symbols to left of head, State of machine, symbol head is scanning and all
symbols to right of head, i.e.

Example of Turing machine accepting a string with equal numbers of zeros and
ones - this can't be done with FA, as was previous shown.
Programming Turing machine can be done entirely in finite state logic, but can
also be done with information on tape.
Finite state logic can also be used to store information, by including tape symbol
dependent states.

9. Define LR(0) items.


The LR (0) item for Grammar G consists of a production in which symbol dot (.) is inserted
at some position in R.H.S of production.
For Example − For the production S → ABC, the generated LR (0) items will be −
S →∙ ABC
S → A ∙ BC
S → AB ∙ C
S → ABC ∙
Production S → ε generates only one item, i.e., S →∙
Canonical LR (0) collection helps to construct LR parser called Simple LR (SLR) parser.
10. What is meant by “Handle Pruning”?
HANDLE PRUNING is the general approach used in shift-and-reduce parsing.

A Handle is a substring that matches the body of a production. Handle reduction is a step
in the reverse of rightmost derivation. A rightmost derivation in reverse can be obtained
by handle pruning.
PART B – (5 * 11 = 55 marks)
Answer ALL questions.
UNIT – I
11. State the difference between 𝜺-NFA, NFA and DFA. Convert the above given 𝜺-NFA to
NFA.
12. Represent the following NFA using a transition diagram. Construct a DFA equivalent to
the NFA given below.
ᵟ 0 1
P {P,Q} P
Q R R
R S ᵠ
*S S S
UNIT II

13. (a) Construct an NFA equivalent to the regular expression 10+(0+11)0*1.


(b) State the pumping lemma for regular languages. Prove that the following is not a
regular language using the pumping lemma.
L = {0n1m | n<m, n>=0, m>0}

Let L be a regular language and let Z be a word of L such that |z|>=n,


Where n is the minimum number of DFA states required for recognizing L, then we can write
z=uvw
Where |uv|<=n and 1<=|v|<=n.
Such that all strings of the form
uv^iw for i>=0 would belong to L.
Proof:
Let L be a regular language
Let z=0^i 1^i |z|>=i
Where i is a P.L constant
Then as per P.L,
We write z=uvw
Where |uv|<=i and 1<=|v|<=i
Such that all strings of the form
uv^iw for i>=0 would belong to L.
i=2, | uv^2w |=|uvw|+|v|
1<=|v|<=i
Add |uvw| on all the sides
1+2i<=| uv^2w |<=i+2i
2i<| uv^2w |<3i+1
Now,
0^n 1^n
n=1 |01|=2 i=1
n=2 |0011|=4 2<| uv^2w |<4
Therefore, L cannot contains any string of length 3,
L is not regular

Or
14. Convert the given CFG to GNF
S  ABA
AaA|𝜺
BaB|𝜺

UNIT III
15. Write in detail about recursive languages and recursively enumerable languages. Also
explain briefly about the Church Turing hypothesis.

1. Recursive enumerable language:

A language L is called a recursive enumerable language if

(i) There is a TM that accepts L and


(ii) Rejects L’ or goes into an infinite loop

i.e. The TM can halt in the accepting state but need not halt in the non accepting state.

2. A language L is said to be recursive if

(i) There is a Turing machine that accepts L and


(ii) Rejects L’

i.e. Here the TM can halt (1) in the accepting states and (2) in the non accepting state.

A recursive language is recursive enumerable but not the converse.

i.e. A recursive language need not be recursive.

Properties of a recursive or recursive enumerable language:

Result 1:
If a language is recursive then it is recursive enumerable.
Result 2: Recursive languages are closed under complementation.

i.e. If L is recursive then its complement is recursive

To prove: The complement of L say L’ is recursive

Proof: Let L be a recursive language. Then there is a Turing Machine M that accepts L.
.
Construct a Turing machine M’ from M such that : M enters a final state on the input W
in L, then M’ halts in a non accepting state. (Without accepting)
If M halts without accepting then M’ accepts the input ‘w’ in L’. Hence M’ is an algorithm
and is given as below.

W Yes Yes
M
Start No No

Here ‘Yes’ corresponds to ‘accept’ and ‘No’ corresponds to ‘Reject’. The language of M’ is
L (M’) and is the complement of L. Hence the proof.

Result 3: The union of two recursive language is recursive.

To prove: L1U L2 is recursive.

Proof: Let L1 and L2 two recursive languages. Then there exists Turing machine M1 and M2 such
that M1 and M2 accept L1 and L2 respectively.

Construct a Turing machine M that accepts L1U L2 as below:

 First simulate M on M1.


 If M1 accepts inputs w in L1U L2 then M accepts.
 If mot, M simulates M2 and accepts iff M2 accepts.

Since M1 and M2 are algorithms (used to say Yes or No), M1 and M2 will not hang, they will halt (in
accepting state or non accepting state). M will surely halt (It will not hang).
Hence M is an algorithm. M is given below:

W
Yes
M1 No
Start
Start
M2 No

Now the language of M is L1U L2. Hence the result.

Result 4: The union of two recursively enumerable languages enumerable.

Proof: Let L and L2 be two recursively enumerable languages.

There are Turing machine M1 and M2 such that M1 accepts L1 and M2 accepts L2. Construct a
Turing machine M that accepts L1U L2 as below:

The above procedure will not work here. Since M1 may not halt for some input W in L1. Hence
M is constructed as below

M1 Yes
Yes

M2 Yes

Now the language of M is L1U L2 . Hence L1U L2 is recursive enumerable.

Result 5: If a language L and its complement L’ are both recursively enumerable, then L ( and
hence L’ by result 2 ) is recursive.

To prove: L is recursive

Proof: Let a language L and its complement L’ are recursively enumerable. Then there are Turing
machine M1 and M2 that accepts L and L’ respectively.

Construct a Turing machine M that accepts L and say either ‘Yes’ or ‘No’ as below: M is
connected in such a way that M simulate M1 and M2 simultaneously.
 If M1 accepts then M will accept it.
 If M2 accepts then M will reject it.

Hence M will always say either ‘yes’ or ‘no’ and not both.

Hence M is an algorithm that accepts that accepts L. Hence L is recursive. {Proved Ans (1) } Hence
L’ is recursive. {Ans (2)}

M is shown below:

M1 Yes Yes
W

Start
M2 Yes No

Hence we have If L and L’ are a pair of complementary languages then either

i. Both L and L’ are recursive (or)


ii. Neither L nor L’ are recursively enumerable.

CHURCH–TURING’S THESIS

Alan Turing defined Turing machines in an attempt to formalize the notion of an “effective
producer” which is usually called as ‘algorithm’ these days. Simultaneously mathematicians were
working independently on the same problem.

Emil Post → Production Systems


Alonzo Church → Lambda Calculus
Noam Chomsky → Unrestricted Grammars
Stephen Kleene → Recursive function Theory
Raymond Smullyn → Formal Systems.

All of the above formalisms were proved equivalent to one another. This led to
(a) Turing’s Thesis (Weak Form): A Turing machine can compute anything that can be
computed by a general-purpose digital computer.

(b) Turing’s Thesis (Strong Form): A Turing machine can compute anything that can be
computed.

The strong form of Turing’s Thesis cannot be proved it states a relationship between
mathematical concepts and the “real world”.

1.4.1 Counting
Two sets can be put into a one-to-one corresponding if and only if they have
exactly the same number of elements.
Example: {red, yellow, green, blue}

{apple, banana, cucumber, plum}


One-to-one correspondence with a subset of natural numbers can be done as:
{red, yellow, green, blue}
↓ ↓ ↓ ↓

{1, 2, 3, 4}
1.4.2 Recursive and Recursively Enumerable Language
There are three possible outcomes of executing a Turing machine over a given
input.
The Turing machine may
(i) Halt and accept the input
(ii) Halt and reject the input, or
(iii) Never halt.

A language is “recursive” if there exists a Turing machine that accepts every string of
language and rejects every string over the same alphabet that is not in the language.

If a language L is recursive, then its complement L should also be recursive.

A language is “recursively enumerable” if there exists a Turing machine that accepts every
string of the language, and does not accept strings that are not in the language. Strings which are
not in the language may be rejected or may cause the Turing machine to go into an infinite loop.

Every Recursive language is also recursively enumerable. But it is not clear if every
recursively enumerable language is also recursive. Turing Machines are not “recursive”. The
terminology is borrowed from recursive function theory.
Or
16. Construct a Turing machine for
L = {aibjck | i*j = k, i, j, k>=1}

UNIT IV
17. Construct a PDA by empty stack, that accepts the language recognized by the grammar,
S  0S1 | A
A  1A0 | S | 𝜺
Check whether the string 0101 is accepted by that PDA.

The CFG can be first simplified by eliminating unit productions:

1. S → 0S1 | 1S0 | ε

Now we will convert this CFG to GNF:

1. S → 0SX | 1SY | ε
2. X → 1
3. Y → 0

The PDA can be:


R1: δ(q, ε, S) = {(q, 0SX) | (q, 1SY) | (q, ε)}
R2: δ(q, ε, X) = {(q, 1)}
R3: δ(q, ε, Y) = {(q, 0)}
R4: δ(q, 0, 0) = {(q, ε)}
R5: δ(q, 1, 1) = {(q, ε)}

Or
18. Design a PDA which accepts all strings which can be derived from the following
Grammar Taking a suitable example string, verify the machine.

S  0B | 1A

A  0 | 0S | 1AA

B  1 | 1S | 0BB

The PDA can be given as:

1. A = {(q), (0, 1), (S, B, 0, 1), δ, q, S, ?}

The production rule δ can be:

R1: δ(q, ε, S) = {(q, 0BB)}


R2: δ(q, ε, B) = {(q, 0S) | (q, 1S) | (q, 0)}
R3: δ(q, 0, 0) = {(q, ε)}
R4: δ(q, 1, 1) = {(q, ε)}

Testing 0104 i.e. 010000 against PDA:

δ(q, 010000, S) ⊢ δ(q, 010000, 0BB)


⊢ δ(q, 10000, BB) R1
⊢ δ(q, 10000,1SB) R3
⊢ δ(q, 0000, SB) R2
⊢ δ(q, 0000, 0BBB) R1
⊢ δ(q, 000, BBB) R3
⊢ δ(q, 000, 0BB) R2
⊢ δ(q, 00, BB) R3
⊢ δ(q, 00, 0B) R2
⊢ δ(q, 0, B) R3
⊢ δ(q, 0, 0) R2
⊢ δ(q, ε) R3
ACCEPT

Thus 0104 is accepted by the PDA.

UNIT V

19. Check whether the following grammar is a LL(1) grammar. Also define the FIRST and
FOLLOW prodecures.

S  iEtS | iEiSeS | a

Eb

Or

20. Construct the CLR and LALR parsing table for the following grammar.
S  CC
C  cC
Cd

You might also like