CS GATE 2014 PAPER 03 - Online Test

Q1. 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 D
Explaination / 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.

Q2. 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 B
Explaination / 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.

Q3.  Consider the following relational schema:
Employee (empId, empName, empDept) 
Customer (custId,custName, salesRepId, rating) 
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 D
Explaination / 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.

Q4. Which number does not belong in the series? 2, 5, 10, 17, 26, 37, 50, 64
Answer : Option C
Explaination / Solution:
No Explaination.


Q5.
The table below has question-wise data on the performance of students in an examination. The marks for each question are also listed. There is no negative or partial marking in the examination.

What is the average of the marks obtained by the class in the examination? 
Answer : Option C
Explaination / Solution:

Total question 
44×2=88 
44×3=132 
144 = 88 
132   308
Total marks obtained= (21×2) + (15×3) + (23×2) =133
Total Number of students=44 
Average = 133/44 = 3.02 

Q6. A dance programme is scheduled for 10.00 a.m. Some students are participating in the programme and they need to come an hour earlier than the start of the event. These students should be accompanied by a parent. Other students and parents should come in time for the programme. The instruction you think that is appropriate for this is
Answer : Option B
Explaination / Solution:
No Explaination.


Q7. Consider the equation: (7526)8 - (Y)8 = (4364)8 , where (X)N stands for X to the base N. Find Y.
Answer : Option C
Explaination / Solution:
No Explaination.


Q8. he ratio of male to female students in a college for five years is plotted in the following line graph. If the number of female students in 2011 and 2012 is equal, what is the ratio of male students in 2012 to male students in 2011?

Answer : Option C
Explaination / Solution:

Take number of female students in 2011=100 ∴ Number of male in 2011=100 No. of female in 2012=100 No. of male in 2012=150 Ratio = 150/100 = 1.5:1

Q9. Let X and Y be finite sets and f : X → Y be a function. Which one of the following statements is TRUE?
Answer : Option D
Explaination / Solution:



Q10. Which one of the following statements is TRUE about every n × n matrix with only real eigenvalues?
Answer : Option A
Explaination / Solution:

If the trace of the matrix is positive and the determinant of the matrix is negative then atleast one of its eigen values is negative. Since determinant = product of eigen values.