GATE 2020
64 questions
MCQ 41 · NAT 231-mark 29 · 2-mark 35
Questions 51–55 of 64
The number of permutations of the characters in LILAC so that no character appears in its original position, if the two L's are indistinguishable, is ______.
Answer: 12
Positions: 1 L, 2 I, 3 L, 4 A, 5 C. The L's cannot go in positions 1 or 3. So they take 2 of {2, 4, 5}:
- L's at {2, 4}: I, A, C fill 1, 3, 5, and C is not at 5 3! 2 = 4
- L's at {2, 5}: fill 1, 3, 4, and A is not at 4 4
- L's at {4, 5}: fill 1, 2, 3, and I is not at 2 4
Total = 12
Answer: 12
- L's at {2, 4}: I, A, C fill 1, 3, 5, and C is not at 5 3! 2 = 4
- L's at {2, 5}: fill 1, 3, 4, and A is not at 4 4
- L's at {4, 5}: fill 1, 2, 3, and I is not at 2 4
Total = 12
Answer: 12
Consider a non-pipelined processor operating at 2.5 GHz. It takes 5 clock cycles to complete an instruction. You are going to make a 5-stage pipeline out of this processor. Overheads associated with pipelining force you to operate the pipelined processor at 2 GHz. In a given program, assume that 30% are memory instructions, 60% are ALU instructions and the rest are branch instructions. 5% of the memory instructions cause stalls of 50 clock cycles each due to cache misses and 50% of the branch instructions cause stalls of 2 cycles each. Assume that there are no stalls associated with the execution of ALU instructions. For this program, the speedup achieved by the pipelined processor over the non-pipelined processor (round off to 2 decimal places) is________.
Answer: 2.15 to 2.18
Non-pipelined: One instruction takes 5 cycles. At 2.5 GHz one cycle is 0.4 ns, so each instruction takes 2 ns.
Pipelined: CPI is 1 plus the stall cycles, so CPI = . At 2 GHz one cycle is 0.5 ns, so each instruction takes 0.925 ns.
Speedup = 2 / 0.925 2.16
Answer: 2.16
Pipelined: CPI is 1 plus the stall cycles, so CPI = . At 2 GHz one cycle is 0.5 ns, so each instruction takes 0.925 ns.
Speedup = 2 / 0.925 2.16
Answer: 2.16
A processor has 64 registers and uses 16-bit instruction format. It has two types of instructions: I-type and R-type. Each I-type instruction contains an opcode, a register name, and a 4-bit immediate value. Each R-type instruction contains an opcode and two register names. If there are 8 distinct I-type opcodes, then the maximum number of distinct R-type opcodes is _______.
Answer: 14
Register field takes bits.
- I-type: opcode + 6 + 4 = 16 gives a 6-bit opcode.
- R-type: opcode + 6 + 6 = 16 gives a 4-bit opcode.
Using expanding opcodes: take one 4-bit R-type code and add 2 more bits. This gives 4 I-type opcodes. So the 8 I-type opcodes use up 8/4 = 2 of the 16 four-bit codes.
R-type opcodes = 16 2 = 14
Answer: 14
- I-type: opcode + 6 + 4 = 16 gives a 6-bit opcode.
- R-type: opcode + 6 + 6 = 16 gives a 4-bit opcode.
Using expanding opcodes: take one 4-bit R-type code and add 2 more bits. This gives 4 I-type opcodes. So the 8 I-type opcodes use up 8/4 = 2 of the 16 four-bit codes.
R-type opcodes = 16 2 = 14
Answer: 14
For n2, let be a non-zero vector. Suppose that x is chosen uniformly at random from . Then, the probability that is an odd number is______
Answer: 0.5
Choose an index j where . Fix the values of all the other to anything you like. Then changing from one value to the other switches the sum between odd and even. So exactly half of all x give an odd sum.
Answer: 0.5
Answer: 0.5
Consider the following C functions.
The return value of fun2(5) is ______
int fun1(int n) {
static int i = 0;
if (n > 0) {
++i;
fun1(n-1);
}
return(i);
} int fun2(int n) {
static int i = 0;
if (n > 0) {
i = i + fun1(n);
fun2(n-1);
}
return(i);
}The return value of fun2(5) is ______
Answer: 55
Each function has its own static i, and neither one is ever reset. Every call to fun1(n) raises fun1's i by n and returns that value.
fun2(5) adds these values to fun2's i: fun1(5), fun1(4), , fun1(1).
- fun1(5) = 5, fun1(4) = 9, fun1(3) = 12, fun1(2) = 14, fun1(1) = 15
So fun2's i = 5 + 9 + 12 + 14 + 15 = 55
Answer: 55
fun2(5) adds these values to fun2's i: fun1(5), fun1(4), , fun1(1).
- fun1(5) = 5, fun1(4) = 9, fun1(3) = 12, fun1(2) = 14, fun1(1) = 15
So fun2's i = 5 + 9 + 12 + 14 + 15 = 55
Answer: 55