GATE 2018
65 questions
MCQ 41 · NAT 241-mark 30 · 2-mark 35
Questions 41–45 of 65
Assume that multiplying a matrix G1 of dimension pxq with another matrix G2 of dimension qxr requires pqr scalar multiplications. Computing the product of n matrices G1G2G3...Gn can be done by parenthesizing in different ways. Define Gi Gi+1 as an explicitly computed pair for a given paranthesization if they are directly multiplied. For example, in the matrix multiplication chain G1G2G3G4G5G6 using parenthesization (G1(G2G3))(G4(G5G6)), G2G3 and G5G6 are the only explicitly computed pairs. Consider a matrix multiplication chain F1F2F3F4F5, where matrices F1, F2, F3, F4 and F5 are of dimensions 2x25, 25x3, 3x16, 16x1 and 1x1000, respectively. In the parenthesization of F1F2F3F4F5 that minimizes the total number of scalar multiplications, the explicitly computed pairs is/are
Answer: (C)
The dimensions are 2, 25, 3, 16, 1, 1000. Multiplying an matrix by a matrix costs .
is . Its left partner is some product of size , and that last step costs . For this is 2000. For the sizes are , so the step costs at least 3000, which is already more than the total below. So is multiplied last with the product of , which is a matrix, costing 2000.
Now find the cheapest way to multiply :
- : , then , then . Total 173.
- : .
- : .
- Any grouping with first costs at least .
So the minimum for the first four is 173, and the total is . For example, costs 2204, which is more.
In the best grouping, the only pair of original matrices multiplied directly is .
Answer: (C)
is . Its left partner is some product of size , and that last step costs . For this is 2000. For the sizes are , so the step costs at least 3000, which is already more than the total below. So is multiplied last with the product of , which is a matrix, costing 2000.
Now find the cheapest way to multiply :
- : , then , then . Total 173.
- : .
- : .
- Any grouping with first costs at least .
So the minimum for the first four is 173, and the total is . For example, costs 2204, which is more.
In the best grouping, the only pair of original matrices multiplied directly is .
Answer: (C)
Consider the following C code. Assume that unsigned long int type length is 64 bits.
unsigned long int fun(unsigned long int n){
unsigned long int i, j = 0, sum = 0;
for (i = n; i > 1; i = i/2) j++;
for ( ; j > 1; j = j/2) sum++;
return(sum);
} The value returned when we call fun with the input isAnswer: (B)
The first loop keeps halving until it reaches 1. This gives j = 40.
Now the second loop runs. Start with j = 40 20 10 5 2 1. The loop adds 1 to sum each time j is 1, so it runs 5 times.
Answer: 5
Now the second loop runs. Start with j = 40 20 10 5 2 1. The loop adds 1 to sum each time j is 1, so it runs 5 times.
Answer: 5
Consider the unsigned 8-bit fixed point binary number representation below,
where the position of the binary point is between . Assume is the most significant bit. Some of the decimal numbers listed below cannot be represented exactly in the above representation:
(i) 31.500 (ii) 0.875 (iii) 12.100 (iv) 3.001
Which one of the following statements is true?
where the position of the binary point is between . Assume is the most significant bit. Some of the decimal numbers listed below cannot be represented exactly in the above representation:
(i) 31.500 (ii) 0.875 (iii) 12.100 (iv) 3.001
Which one of the following statements is true?
Answer: (C)
The format has 5 integer bits () and 3 fraction bits (). So it can show only multiples of , from to .
- (i) is a multiple of and is in range, so it can be represented exactly ().
- (ii) can be represented exactly ().
- (iii) : the fraction is not a multiple of , so it cannot be represented exactly.
- (iv) : the fraction is not a multiple of , so it cannot be represented exactly.
So only (iii) and (iv) cannot be represented exactly.
Answer: (C)
- (i) is a multiple of and is in range, so it can be represented exactly ().
- (ii) can be represented exactly ().
- (iii) : the fraction is not a multiple of , so it cannot be represented exactly.
- (iv) : the fraction is not a multiple of , so it cannot be represented exactly.
So only (iii) and (iv) cannot be represented exactly.
Answer: (C)
The size of the physical address space of a processor is bytes. The word length is bytes. The capacity of cache memory is Bytes. The size of each cache block is words. For a K-way set-associative cache memory, the length (in number of bits) of the tag field is
Answer: (B)
The block has words of bytes, so it is bytes. The block offset therefore has bits.
Number of blocks in the cache .
With K blocks in each set, number of sets .
So the set index has bits.
The address has P bits, so
M and W cancel, so options (C) and (D), which still contain them, are wrong. Option (A) has the sign of wrong: more ways mean fewer sets, a shorter index, and so a longer tag.
Answer: (B)
Number of blocks in the cache .
With K blocks in each set, number of sets .
So the set index has bits.
The address has P bits, so
M and W cancel, so options (C) and (D), which still contain them, are wrong. Option (A) has the sign of wrong: more ways mean fewer sets, a shorter index, and so a longer tag.
Answer: (B)
Consider the following languages:
I.
II.
III.
IV.
Which of the languages above are context-free?
I.
II.
III.
IV.
Which of the languages above are context-free?
Answer: (B)
- I: means , so one signed counter is enough. Keep it on the stack: it holds either some A's (counter positive) or some B's (counter negative), never both. Each a or c adds one: pop a B if the top is B, else push A. Each b or d subtracts one: pop an A if the top is A, else push B. Accept if the stack is empty at the end. It is a CFL.
- II: is followed by : . It is a CFL.
- III: this is with . Erase the d's with a homomorphism (d to empty). For any n we can pick , so the image is , which is not context-free. CFLs are closed under homomorphism, so III is not a CFL.
- IV: intersect with the regular language (no d's, so ). This leaves . Take and . Then vxy cannot touch both a's and c's, since the b's between them number p. Pump up once more (i = 2); the pumped part adds a's, b's and c's, not all zero.
If : the c's stay at but , so the string is not in the language.
If : then , and we would need , that is . If this gives , a contradiction. If then , but , a contradiction.
So IV is not a CFL.
Answer: (B)
- II: is followed by : . It is a CFL.
- III: this is with . Erase the d's with a homomorphism (d to empty). For any n we can pick , so the image is , which is not context-free. CFLs are closed under homomorphism, so III is not a CFL.
- IV: intersect with the regular language (no d's, so ). This leaves . Take and . Then vxy cannot touch both a's and c's, since the b's between them number p. Pump up once more (i = 2); the pumped part adds a's, b's and c's, not all zero.
If : the c's stay at but , so the string is not in the language.
If : then , and we would need , that is . If this gives , a contradiction. If then , but , a contradiction.
So IV is not a CFL.
Answer: (B)