GATE 2014 (Session 1)
65 questions
MCQ 40 · NAT 251-mark 30 · 2-mark 35
Questions 51–55 of 65
Consider the following C function in which size is the number of elements in the array E:
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;
} The value returned by the function MyX is theAnswer: (A)
At the start, Y holds the sum of the whole array. The whole array is also a sub-array.
Next, the nested loops find the sum Z of each sub-array E[i..j]. Whenever Z is bigger than Y, Y is updated. So Y ends up as the largest sub-array sum.
Answer: maximum possible sum of elements in any sub-array of array E
Next, the nested loops find the sum Z of each sub-array E[i..j]. Whenever Z is bigger than Y, Y is updated. So Y ends up as the largest sub-array sum.
Answer: maximum possible sum of elements in any sub-array of array E
Consider the following pseudo code. What is the total number of multiplications to be performed?
D= 2
for i = 1 to n do
for j = i to n do
for k = j + 1 to n do
D = D * 3 Answer: (C)
For fixed i and j, the innermost loop runs from to n, which is times.
For a given j, the middle loop reaches it for every , so there are j such values of i. The total number of multiplications is:
This is one-sixth of the product of 3 consecutive integers, (equal to ).
Answer: (C)
For a given j, the middle loop reaches it for every , so there are j such values of i. The total number of multiplications is:
This is one-sixth of the product of 3 consecutive integers, (equal to ).
Answer: (C)
Consider a 6-stage instruction pipeline, where all stages are perfectly balanced. Assume that there is no cycle-time overhead of pipelining. When an application is executing on this 6-stage pipeline, the speedup achieved with respect to non-pipelined execution if 25% of the instructions incur 2 pipeline stall cycles is _________.
Answer: 4
The CPI of the pipeline = 1 + 0.25 2 = 1.5. With all 6 stages balanced, the ideal speedup is 6.
Speedup = 6 / 1.5 = 4
Answer: 4
Speedup = 6 / 1.5 = 4
Answer: 4
An access sequence of cache block addresses is of length N and contains n unique block addresses. The number of unique block addresses between two consecutive accesses to the same block address is bounded above K. What is the miss ratio if the access sequence is passed through a cache of associativity Ak exercising least-recently-used replacement policy?
Answer: (A)
Between two accesses to the same block, at most k other blocks are used. With LRU, the cache keeps A k blocks per set. So a block is never removed before it is used again. Only the first access to each of the n distinct blocks is a miss.
Miss ratio = n / N
Answer: n/N
Miss ratio = n / N
Answer: n/N
Consider the 4-to-1 multiplexer with two lines S1 and S0 given below.
The minimal sum of-products form of the Boolean expression for the output F of the multiplexer is
The minimal sum of-products form of the Boolean expression for the output F of the multiplexer is
Answer: (A)
From the figure, the select lines are and , and the data inputs are .
Simplify the first and last terms using :
So .
This is minimal: F is 1 for . The term (101) has no neighbour that is 1, and the other three cells are covered by (010, 011) and (010, 110), both needed.
Answer: (A)
Simplify the first and last terms using :
So .
This is minimal: F is 1 for . The term (101) has no neighbour that is 1, and the other three cells are covered by (010, 011) and (010, 110), both needed.
Answer: (A)