Q1. Consider the relational schema given below, where eId of the relation dependentis a foreign
key referring to empId of the relation employee. Assume that every employee has at least one
associated dependent in the dependent relation.
employee (empId, empName, empAge)
dependent (depId, eId, depName, depAge)
Consider the following relational algebra query
The above query evaluates to the set of empIds of employees whose age is greater than that of
Answer : Option DExplaination / Solution:
Part A of the above given relational algebra query will give the set of empIds of those
employees whose age is less than or equal to the age of some of his/her dependents.
Now when set of empIds of all employees minus set of empIds obtained from part A is done,
then we get the set of empIds of employees whose age is greater than that of all of his/her
dependents.
Q3. Consider the decision problem 2CNFSAT defined as follows:
{ φ | φ is a satisfiable propositional formula in CNF with at most two literal per clause}
For example, is a Boolean formula and it is in 2CNFSAT.
The decision problem 2CNFSAT is
Answer : Option BExplaination / Solution:
2 SAT is in P. This we can prove by reducing 2 SAT to directed graph reachability problem
which is known to be in P.
Procedure for reducing 2 SAT to reachability problem:
1. Let ϕ be CNF with clauses of length 2 and let P be the set of propositional
variables(literals) in ϕ
2. Build a graph G=(V,E) with V= P { p|p P} ∪ ¬ ∈ and (x, y E )∈ iff there is a clause in ϕ
that is equivalent to x y → (all the clauses are converted to equivalent implications and
the graph built is called as implication graph)
3. Observe that ϕ is unsatisfiable iff there is a p P ∈ such that there is both a path from p to
to ¬p and from ¬p to p in G.
This condition can be tested by running the reachability algorithm several times.
Q4.Which one of the following problems is undecidable?
Answer : Option AExplaination / Solution:
There were algorithms to find the membership of CFG (using CYK algorithm) and finiteness
of CFG (using CNF graph) and emptiness. But there is no algorithm for ambiguity of CFG,
so it is undecidable.
Consider the following languages over the alphabet Σ = {0,1,c}
Here wr is the reverse of the string w. Which of these languages are deterministic Contextfree
languages?
Answer : Option CExplaination / Solution:
For the languages L1 and L2 we can have deterministic push down automata, so they are
DCFL’s, but for L3 only non-deterministic PDA possible. So the language L3 is not a
deterministic CFL.
Q7. Let A be a square matrix size n × n. Consider the following pseudocode. What is the
expected output?
C = 100;
for i = 1 to n do
for j = 1 to n do
{
Temp = A[ i ] [ j ] + C ;
A [ i ] [ j ] = A [ j ] [ i ] ;
A [ j ] [ i ] = Temp – C ;
}
for i = 1 to n do
for j = 1 to n do
output (A[ i ] [ j ]);
Answer : Option AExplaination / Solution:
In the computation of given pseudo code for each row and column of Matrix A, each upper
triangular element will be interchanged by its mirror image in the lower triangular and after
that the same lower triangular element will be again re-interchanged by its mirror image in
the upper triangular, resulting the final computed Matrix A same as input Matrix A.
Q8.Consider the following rooted tree with the vertex labelled P as the root
The order in which the nodes are visited during an in-order traversal of the tree is
Answer : Option AExplaination / Solution:
The In order Traversal of Ternary Tree is done as follows:
Left → Root → Middle → Right
So the nodes are visited in SQPTRWUV order.
Q9.You have an array of n elements. Suppose you implement quick sort by always choosing the
central element of the array as the pivot. Then the tightest upper bound for the worst case
performance is
Answer : Option AExplaination / Solution:
The Worst case time complexity of quick sort is O(n2). This will happen when the elements
of the input array are already in order (ascending or descending), irrespective of position of
pivot element in array.