toc-solved-nov-dec-2022
toc-solved-nov-dec-2022
[Nov_Dec_2022]
SPPU TE 🎖📚
SOLVED QUESTION PAPER
Theory of Computation
Q1)
ANS
Original Grammar:
S→XB | AA
A→ a | SA
B→ b
X→ a
Telegram Channel
https://t.me/SPPU_TE_BE_COMP
(for all engineering Resources)
WhatsApp Channel
(for all tech updates)
https://whatsapp.com/channel/
0029ValjFriICVfpcV9HFc3b
Insta Page
(for all engg & tech updates)
https://www.instagram.com/
sppu_engineering_update
lOMoARcP SD| 4398 079 5
To convert to GNF, we need to eliminate ε-productions and make sure all productions are of the form
A→aα.
Step 1: The production rule A → SA is not in GNF, so we substitute S → XB | AA in the production rule
A → SA as:
S → XB | AA
A → a | XBA | AAA
B→b
X→a
Step 2: The production rule S → XB and B → XBA is not in GNF, so we substitute X → a in the production
rule S → XB and B → XBA as:
S → aB | AA
A → a | aBA | AAA
B→b
X→a
Step 3: Now we will remove left recursion (A → AAA), we get:
S → aB | AA
A → aC | aBAC
C → AAC | ε
B→b
X→a
Step 4: Now we will remove null production C → ε, we get:
S → aB | AA
A → aC | aBAC | a | aBA
C → AAC | AA
B→b
X→a
Step 5: The production rule S → AA is not in GNF, so we substitute A → aC | aBAC | a | aBA in
production rule S → AA as:
S → aB | aCA | aBACA | aA | aBAA
A → aC | aBAC | a | aBA
C → AAC
C → aCA | aBACA | aA | aBAA
B→b
X→a
Step 6: The production rule C → AAC is not in GNF, so we substitute A → aC | aBAC | a | aBA in
production rule C → AAC as:
S → aB | aCA | aBACA | aA | aBAA
A → aC | aBAC | a | aBA
C → aCAC | aBACAC | aAC | aBAAC
C → aCA | aBACA | aA | aBAA
B→b
X→a
OR
Q2)
As we can see, the string "ibtbes" has mul琀椀ple le昀琀most deriva琀椀ons, which implies that the given grammar
Is ambiguous.
Step 1: Convert remaining produc琀椀ons to binary produc琀椀ons (produc琀椀ons with at most two symbols on
the right-hand side).
S → AS1 | BS2 | a | b | AS3 | BS4
S1 → a
S2 → b
S3 → a
S4 → b
Now, the produc琀椀ons sa琀椀sfy the CNF requirements. The final CNF grammar is:
G = ({S, S1, S2, S3, S4}, {a, b}, P', S)
P' = {S → AS1 | BS2 | a | b | AS3 | BS4,
S1 → a
S2 → b,
S3 → a,
S4 → b}
ANS
Given grammar
E → E * E | E - E | id
Q3)
L={w∈{a,b}* |w is of the a^n b^n with n≥ 1} through both empty stack andfinal
state and demonstrates the stack operation for the string aaabbb.
ANS A Pushdown Automaton (PDA) is a finite automaton with an additional stack memory.
The PDA for this language can be represented by the 7-tuple
(Q,Σ,Γ,δ,q0,Z,F).
Now, let's demonstrate the stack operation for the string "aaabbb":
(q_0, aaabbb, Z) -> (q_0, aabbb, XZ) // Push X onto the stack for 'a'
(q_0, aabbb, X) -> (q_0, abbb, XX) // Push X onto the stack for 'a'
(q_0, abbb, X) -> (q_0, bbb, X) // Pop X from the stack for 'b'
(q_1, bbb, \varepsilon) -> (q_1, bb, \varepsilon) // Pop X for 'b'
(q_1, bb, \varepsilon) -> (q_1, b, \varepsilon) // Pop X for 'b'
(q_1, b, \varepsilon) -> (q_1, \varepsilon, \varepsilon) // Pop X for 'b'
(q_f, \varepsilon, Z) // Accept as the stack is empty
(q0, a, z)
(q0, az)
(q0, a, a)
(q0, aa)
(q0, b, a)
(q1, \epsilon )
(q1, b, a)
(q1, \epsilon )
(q1, \epsilon, z)
(qf, z)
Whenever ‘a’ comes, push ‘a’ two times in the stack and if ‘a’ comes again then do the same.When ‘b’
comes then pop one ‘a’ from the stack each time. Note that b comes after ‘a’.
Finally at the end of the strings, if nothing is left in the STACK, then we can declare that language is
accepted in the PDA.
The PDA for the problem is as follows –
Transition functions
(q0, a, z)
(q1, az)
(q0, a, z)
(q3, aaz)
(q1, a, a)
(q1, aa)\
(q1, b, a)
(q2, \epsilon)
(q2, b, a)
(q2, \epsilon)
(q2, \epsilon, z)
(qf1, z)
(q3 a, a)
(q3, aaa)
(q3, b, a)
(q4, \epsilon)
(q4, b, a)
(q4, \epsilon)
(q4, \epsilon, z)
(qf2, z)
OR
Q4)
a) Design a PDA for accepting a language {0^n 1^m 0^n | m, n>=1}. [9]
Simulate this PDA for the input string “0011100”
ANS
In this PDA, n number of 0's are followed by any number of 1's followed n number of 0's. Hence the logic
for design of such PDA will be as follows:
Push all 0's onto the stack on encountering first 0's. Then if we read 1, just do nothing. Then read 0, and
on each read of 0, pop one 0 from the stack.
Now, let's simulate the PDA for the input string "0011100":
(q0,0,z0) = (q0,z0)
(q0,0,0) = (q0,00)
(q0,1,0) = (q1,10)
(q0,1,1) = (q1,11)
(q0,2,1) =(q2, ε)
(q0,2,1) =( q2, ε)
(q0,3,0) = (q3, ε)
(q0,3,0) = (q3, ε)
(q0, ε,z0) =(q4,z0)
(q0,1,z0) =(q5,1z0)
(q0,1,1) =( q5,11)
(q0,2,1) =(q6, ε)
(q0,2,1) =( q6, ε)
(q0, ε,z0) =(q4,z0)
(q0,3,0) =( q3, ε)
(q0, ε,z0) =(q4,z0)
ANS
It doesn’t have the capability or space to store long It has the additional stack for storing long
sequence of input alphabets. sequence of alphabets.
Finite Automata can be constructed for Type-3 Pushdown Automata can be constructed for Type-
grammar 2 grammar.
Q5)
a) Write a short note on Halting problem of Turing machine. [4]
ANS
The halting problem is a decision problem about properties of computer programs on a fixed Turing-
complete model of computation, i.e., all programs that can be written in some given programming
language that is general enough to be equivalent to a Turing machine.
b) Design a Turing Machine for the following language by Considering transition table and diagram.
i) TM That erases all non blank symbols on the tape where the sequence of non blank [9]
symbols does not contain any blank symbol B in between.
ii) TM that find 2’s complement of a binary machine. c) Design a Turing Machine that reads a
string representing a binary number and erases all leading 0’s in the string. However, if the
string comprises of only 0’s it keeps one 0.
ANS
i)
To design a Turing Machine (TM) for the specified language, we need to create a transi琀椀on table and
diagram define how the machine behaves on di昀昀erent inputs.
a/B,R
a/B,R
qq
Q q1
q0
B/B,N
q2 is halt
(q0,a) = (q0,B,R)
(q0,b) = (q0,B,R)
(q1,b) = (q1,B,N)
ii)
Approach for 2's complement:
i. Scan input string from right to left
ii. Pass all consecu琀椀ve '0's
iii. When '1' comes do nothing
iv. A昀琀er that take complement of every digit.
2’s complement of a binary number is 1 added to the 1’s complement of the binary number.
Transition Diagram:
Here, q0 shows the initial state and q1 and q2 shows the transition state and q3 shows the final state.
And 0, 1 are the variables used and R, L shows right and left.
b) Design a Turing Machine that reads a string representing a binary number and erases all leading
0’s in the string. However, if the string comprises of only 0’s it keeps one 0. [5]
ANS
Let us assume that the input string is terminated by a blank symbol, B, at each end of the string.
The Turing Machine, M, can be constructed by the following moves –
Let q0 be the initial state.
If M is in q0, on reading 0, it moves right, enters the state q1 and erases 0. On reading 1, it enters the
state q2 and moves right.
If M is in q1, on reading 0, it moves right and erases 0, i.e., it replaces 0’s by B’s. On reaching the
le昀琀most 1, it enters q2 and moves right. If it reaches B, i.e., the string comprises of only 0’s, it moves
le昀琀 and enters the state q3.
If M is in q2, on reading either 0 or 1, it moves right. On reaching B, it moves le昀琀 and enters the state
q4. This validates that the string comprises only of 0’s and 1’s. If M is in q3, it replaces B by 0, moves
le昀琀 and reaches the final state qf.
If M is in q4, on reading either 0 or 1, it moves left. On reaching the beginning of the string, i.e., when
it reads B, it reaches the final state qf.
Hence,
M = {{q0, q1, q2, q3, q4, qf}, {0,1, B}, {1, B}, δ, q0, B, {qf}}
where δ is given by −
Tape alphabet Present Present Present Present Present
symbol State ‘q0’ State ‘q1’ State ‘q2’ State ‘q3’ State ‘q4’
0 BRq1 BRq1 ORq2 - OLq4
1 1Rq2 1Rq2 1Rq2 - 1Lq4
B BRq1 BLq3 BLq4 OLqf BRqf
OR
Q6)
ANS
Reducibility :
A multi-tape Turing machine is an extension of the classical Turing machine model that
incorporates multiple tapes, each with its own tape head. The machine operates on multiple tapes
simultaneously, and the transition function is defined based on the combination of symbols read from all tapes.
In a multi-tape Turing machine:
Configuration: The configuration of the machine is represented by the content of all tapes and the positions of
the tape heads.
Transition Function: The transition function specifies how the machine transitions between states based on
the symbols read from the current positions of all tape heads.
Computation: During a computation, each tape head moves independently, and the transition function dictates
the next state and the symbols to write on each tape.
The concept of multi-tape Turing machines contributes to the understanding of
computational complexity and the design of algorithms, providing insights into the efficiency of parallel
processing in the context of theoretical computation.
ANS
Step 1: DFA FOR aba*b
a
a b b
q0 q1 q2 q3
Step 2 : DFA to TM
a/a,R
a/a,R b/b,R b/b,R q3
q0 q1 q2
B/B,N
q4
Halt
c)
Design a TM that multiplies two unary numbers over Σ={1}. [8]
Write simulation for the string 11*111
ANS
To design a Turing Machine (TM) that multiplies two unary numbers over the alphabet
Σ={1}, we need to create a machine that performs the multiplication operation for unary numbers.
Unary numbers are represented by sequences of '1's, and multiplication is essentially repeated addition.
*/1,N
q6
INPUT B 1 1 * 1 1 1 B
OUTPUT B 1 1 1 1 1 1 B
OR
Q7)
ANS
let's break down the statement "The halting problem of a Turing machine is undecidable" in simple
terms.
Now, why is it called undecidable? Imagine you have a magical machine (let's call it the Oracle) that
can answer any yes-or-no question about whether a given program will halt or not. We want to know
if this Oracle machine is possible to exist.
Here's a simple way to think about it:
o Assume we have this magical Oracle machine that can tell us whether any program halts or runs
forever.
o Now, let's create a new program (let's call it ParadoxProgram) that uses the Oracle machine to check
whether a modified version of itself will halt or run forever.
o If the Oracle machine says the modified version halts, then ParadoxProgram runs forever. If the Oracle
machine says it runs forever, then ParadoxProgram halts.
o This creates a paradox because no matter what the Oracle machine says, it leads to a contradiction.
Therefore, the initial assumption that we can have a magical Oracle machine that decides the halting
problem must be false. This means that there is no general algorithm (a step-by-step procedure) that can
determine whether any arbitrary program will halt or run forever. Hence, the halting problem for Turing
machines is undecidable.
In simpler terms, it's like saying there's no one-size-fits-all method to predict whether any computer program
will eventually finish or keep going forever. It's a fundamental limit in the world of computation.
b) Define and compare class P and class NP problem with suitable diagram [8]
ANS
P (POLYNOMIAL TIME):
De昀椀ni琀椀on: The complexity class P is the set of all decision problems that can be solved with worst-case
polynomial time-complexity.
Definition: It's a class of problems in computer science where, if you're given a potential solution, you can
quickly check if it's correct. However, finding the solution quickly (in polynomial time) is still an
open question for many problems in NP
All P problems are deterministic in nature. All the NP problems are non-deterministic in
nature
The solution to P class problems is easy to find The solution to NP class problems is hard to find
Examples of P problems are: Selection sort, Examples of NP problems are the Travelling
Linear Search salesman problem and the knapsack problem.
OR
Q8)
ANS
The term "recursively enumerable" is related to the concept of computability in theoretical computer
science.
A set of natural numbers is said to be recursively enumerable if there exists an algorithm (a procedure
or a computer program) that can enumerate its elements one by one. In other words, a set is recursively
enumerable if there is a method to generate its members through an effective procedure.
Formally, a set A is recursively enumerable if there exists a partial recursive function (a computable
function) whose domain is exactly the set A. This means that there is a Turing machine (or an equivalent
computational model) that, when given an input, either halts and outputs 1 if the input belongs to A or
does not halt (runs forever) if the input does not belong to A.
The concept of recursively enumerable sets is closely related to the broader notion of decidability. If a
set is both recursively enumerable and its complement is recursively enumerable, then the set is said to
be decidable.
In summary, a recursively enumerable set is one for which there exists a procedure to generate its
members, even if the procedure might not terminate for inputs not in the set.
3) Vertex Cover:
Given an undirected graph, is there a set of vertices such that every edge in the graph is incident to at
least one vertex in the set?
4) Subset Sum:
Given a set of integers and a target sum, is there a subset of the integers that adds up to the target sum?
6) Knapsack Problem:
Given a set of items, each with a weight and a value, determine the maximum value that can be obtained
by selecting a subset of the items with a total weight not exceeding a given limit.
7) Hamiltonian Cycle:
Given a graph, is there a cycle that visits every vertex exactly once?
8) Clique Problem:
Given an undirected graph, is there a subset of vertices such that every pair of distinct vertices in the
subset is connected by an edge?
9) Integer Factorization:
Given a composite integer, can it be expressed as a product of two non-trivial integers? (This problem is
not known to be in P, but efficient algorithms for it would have significant implications for
cryptography.)
These problems are considered to be in NP because, if someone provides a solution, it can be verified quickly.
However, whether there exist efficient algorithms to find these solutions (i.e., whether P equals NP) is an open
question in computer science.
All P problems are deterministic in nature. All the NP problems are non-deterministic in
nature
The solution to P class problems is easy to find The solution to NP class problems is hard to find
Examples of P problems are: Selection sort, Examples of NP problems are the Travelling
Linear Search salesman problem and the knapsack problem.