## General

 Question 1

There are 5 bags labeled 1 to 5. All the coins in a given bag have the same weight. Some bags have coins of weight 10 gm, others have coins of weight 11 gm. I pick 1, 2, 4, 8, 16 coins respectively from bags 1 to 5. Their total weight comes out to 323 gm. Then the product of the labels of the bags having 11 gm coins is _______.

 A 12 B 13 C 14 D 15
Algorithms       General       GATE 2014 [Set-1]
Question 1 Explanation:
Bags: 1 2 3 4 5
No. of coins picked: 1 2 4 8 16
There are two types of weights of coin, i.e., 10gm and 11gm. And total weight of picked coins are 323gm.
Let there be x number of 10gm coins and y number of 11gm coins.
So, 10x + 11y = 323 ------ (1)
And we also know that total number of coins picked is
1 + 2 + 4 + 8 + 16 = 31 which is equal to x + y, so,
= 31 ------ (2)
Solving equation (1) and (2), we get
y = 13
Means total there are 13 coins of 11gm.
Now we can chose bag number 1, 3 and 4, we will get a total sum of 13 coins picked from them.
So product of labelled bag number = 1×3×4 = 12
 Question 2

The minimum number of comparisons required to find the minimum and the maximum of 100 numbers is __________.

 A 148 B 149 C 150 D 151
Algorithms       General       GATE 2014 [Set-1]
Question 2 Explanation:
The minimum number of comparisons required to find the minimum and the maximum of 100 numbers is 3n/2 – 2 = 148.
(∵ T(n) = T(floor(n/2))+T(ceil(n/2))+2)
 Question 3

Consider the following C function in which size is the number of elements in the array E: The value returned by the function MyX is the

```int MyX(int *E, unsigned int size)
{
int Y = 0;
int Z;
int i, j, k;
for(i = 0; i < size; i++)
Y = Y + E[i];
for(i = 0; i < size; i++)
for(j = i; j < size; j++)
{
Z = 0;
for(k = i; k <= j; k++)
Z = Z + E[k];
if (Z > Y)
Y = Z;
}
return Y;
}
```
 A maximum possible sum of elements in any sub-array of array E. B maximum element in any sub-array of array E. C sum of the maximum elements in all possible sub-arrays of array E. D the sum of all the elements in the array E.
Data-Structures       General       GATE 2014 [Set-1]
Question 3 Explanation:
Y=0
for (i=0; i Y=Y+E[i] // E is an array, this statement calculates the sum of elements of the array E and stores it in Y.
for (i=0; i for(j=i; j {
Z=0;
for(k=i; k<=j; k++)
Z=Z+E[k];
// It calculates the sum of all possible subarrays starting from 0 i.e., the loop will iterate for all the elements of array E and for every element, calculate sum of all sub arrays starting with E[i].
Store the current sum in Z.
If Z is greater than Y then update Y and return Y. So it returns the maximum possible sum of elements in any sub array of given array E.
 Question 4

Consider the expression tree shown. Each leaf represents a numerical value, which can either be 0 or 1. Over all possible choices of the values at the leaves, the maximum possible value of the expression represented by the tree is _______. A 6 B 7 C 8 D 9
Compiler-Design       General       GATE 2014 [Set-2]
Question 4 Explanation:  Question 5

Which of the following statements are CORRECT?

1) Static allocation of all data areas by a compiler makes it impossible to implement recursion.
2) Automatic garbage collection is essential to implement recursion.
3) Dynamic allocation of activation records is essential to implement recursion.
4) Both heap and stack are essential to implement recursion.
 A 1 and 2 only B 2 and 3 only C 3 and 4 only D 1 and 3 only
Compiler-Design       General       GATE 2014 [Set-3]
Question 5 Explanation:
The statement, static allocation of all data areas by a compiler makes it impossible to implement recursion is true, as recursion requires memory allocation at run time, so it requires dynamic allocation of memory. Hence, Dynamic allocation of activation records is essential to implement recursion is also a true statement.
 Question 6

The procedure given below is required to find and replace certain characters inside an input character string supplied in array A. The characters to be replaced are supplied in array oldc, while their respective replacement characters are supplied in array newc. Array A has a fixed length of five characters, while arrays oldc and newc contain three characters each. However, the procedure is flawed

```void find_and_replace(char *A, char *oldc, char *newc) {
for (int i = 0; i < 5; i++)
for (int j = 0; j < 3; j++)
if (A[i] == oldc[j]) A[i] = newc[j];
}```

The procedure is tested with the following four test cases

```(1) oldc = "abc", newc = "dab" (2) oldc = "cde", newc = "bcd"
(3) oldc = "bca", newc = "cda" (4) oldc = "abc", newc = "bac" ```

The tester now tests the program on all input strings of length five consisting of characters ‘a’, ‘b’, ‘c’, ‘d’ and ‘e’ with duplicates allowed. If the tester carries out this testing with the four test cases given above, how many test cases will be able to capture the flaw?

 A Only one B Only two C Only three D All four
Computer-Organization       General       GATE 2013
Question 6 Explanation:
void find_and_replace (char *A, char *oldc, char *newc)
{
for (int i=0; i<5; i++)
for (int j=0; j<3; j++)
if (A[i] = = oldc[j])
A[i] = newc[j];
}
The procedure is tested with the following four test cases.
1. oldc = “abc”, newc = ”dab”
2. oldc = “cde”, newc = ”bcd”
3. oldc = “bca”, newc = ”cda”
4. oldc = “abc”, newc = ”bac”
Given input string of length 5 consisting of a, b, c, d, e, duplicates allowed. Similarly for (4), we done 2 replacements for A with element newc & newc.
Updating the newc value with another newc value is called as a flaw here. Hence 2 flaws.
 Question 7

Which of the following statements is true?

 A ROM is a Read/Write memory B PC points to the last instruction that was executed C Stack works on the principle of LIFO D All instructions affect the flags
Operating-Systems       General       GATE 1995
Question 7 Explanation:
We know that stack works on the principle of LIFO.
There are 7 questions to complete.

Register Now