Q1.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.
Q3.Consider the pseudocode given below. The function Dosomething () takes as argument a
pointer to the root of an arbitrary tree represented by the leftMostChild-rightSibling
representation. Each node of the tree is of type treeNode.
typedef struct treeNode* treeptr;
Struct treeNode
{
Treeptr leftMostchild, rightSibiling;
};
Int Dosomething (treeptr tree)
{
int value =0;
if (tree ! = NULL) {
If (tree -> leftMostchild = = NULL)
else
value = Dosomething (tree->leftMostchild);
value = value + Dosometing (tree->rightsibiling);
}
return (value);
}
When the pointer to the root of a tree is passed as the argument to DoSomething, the value
returned by the function corresponds to the
Answer : Option DExplaination / Solution:
The key to solving such questions is to understand or detect where/by what condition the
value (or the counter) is getting incremented each time.
Here, that condition is if (tree→leftMostchild == Null)
⇒ Which means if there is no left most child of the tree (or the sub-tree or the current nodeas
called in recursion)
⇒ Which means there is no child to that particular node (since if there is no left most child,
there is no child at all).
⇒ Which means the node under consideration is a leaf node.
⇒ The function recursively counts, and adds to value, whenever a leaf node is encountered.
⇒ The function returns the number of leaf nodes in the tree.
Q4.Consider the C function given below. Assume that the array listA contains n (> 0) elements,
sored in ascending order.
int ProcessArray (int * listA, int x, int n)
{
Int 1, j, k;
i = 0;
j = n – 1;
do {
k = (i + j) /2;
if (x < = listA [k])
j = k – 1;
If (listA [k] < = x)
i = k+1;
}while (1 < = j);
If (listA [k] = = x)
return (k) ;
else
return -1;
}
Which one of the following statements about the function ProcessArray is CORRECT?
Answer : Option BExplaination / Solution:
By the logic of the algorithm it is clear that it is an attempted implementation of
Binary Search. So option C is clearly eliminated. Let us now check for options A and
D.
A good way to do this is to create small dummy examples (arrays) and implement the
algorithm as it is. One may make any array of choice. Running iterations of the
algorithm would indicate that the loop exits when the x is not present. So option A is
wrong. Also, when x is present, the correct index is indeed returned. D is also wrong.
Correct answer is B. It is a correct implementation of Binary Search.
SalesRepId is a foreign key referring to empId of the employee relation. Assume that each
employee makes a sale to at least one customer. What does the following query return?
SELECT empName
FROM employee E
WHERE NOT EXISTS (SELECT custId
FROM customer C
WHERE C. salesRepId = E. empId
AND C. rating < > ‘GOOD’)
Answer : Option DExplaination / Solution:
The outer query will return the value (names of employees) for a tuple in relation E, only if
inner query for that tuple will return no tuple (usage of NOT EXISTS).
The inner query will run for every tuple of outer query. It selects cust-id for an employee e, if
rating of customer is NOT good. Such an employee should not be selected in the output of
outer query.
So the query will return the names of all those employees whose all customers have GOOD
rating.
Q6.Let R be the relation on the set of positive integers such that a aRb if and only if a and b are
distinct and have a common divisor other than 1. Which one of the following statements
about R is true?
Answer : Option DExplaination / Solution:
R is not reflexive as each element can‟t be related to itself.
R is symmetric
Let a = 3, b = 6 and c = 10 then 3 and 6 have a common division other than 1
Q7. In the context of abstract-syntax-tree (AST) and control-flow-graph (CFG), which one of the
following is TRUE?
Answer : Option CExplaination / Solution:
Optional (A) is not true when CFG contains cycle
Option (B) is false as CFG can contain cycle
Option (D) is false as a single node can contain block of statements.
Q8.Consider two decision problems Q1, Q2 such that Q1 reduces in polynomial time to 3-SAT
and 3 -SAT reduces in polynomial time to Q2. Then which one of following is consistent with
the above statement?