GATE 2021 (Session 2)
64 questions
MCQ 33 · MSQ 13 · NAT 181-mark 29 · 2-mark 35
Questions 36–40 of 64
Assume a two-level inclusive cache hierarchy, L1 and L2, where L2 is the larger of the two. Consider the following statements.
S1: Read misses in a write through L1 cache do not result in writebacks of dirty lines to the L2
S2: Write allocate policy must be used in conjunction with write through caches and no-write allocate policy is used with writeback caches.
Which of the following statements is correct?
S1: Read misses in a write through L1 cache do not result in writebacks of dirty lines to the L2
S2: Write allocate policy must be used in conjunction with write through caches and no-write allocate policy is used with writeback caches.
Which of the following statements is correct?
Answer: (A)
Let us check each statement.
- S1: an L1 cache that is write-through never holds dirty lines, because every write already goes to L2. So a read miss never writes back a dirty line TRUE.
- S2: the usual pairing is the opposite. Write-allocate goes with write-back, and no-write-allocate goes with write-through. Neither pairing is mandatory FALSE.
Answer: S1 is true and S2 is false
- S1: an L1 cache that is write-through never holds dirty lines, because every write already goes to L2. So a read miss never writes back a dirty line TRUE.
- S2: the usual pairing is the opposite. Write-allocate goes with write-back, and no-write-allocate goes with write-through. Neither pairing is mandatory FALSE.
Answer: S1 is true and S2 is false
Suppose we want to design a synchronous circuit that processes a string of 0's and 1's. Given a string, it produces another string by replacing the first 1 in any subsequence of consecutive 1's by a 0. Consider the following example.
A Mealy Machine is a state machine where both the next state and the output are functions of the present state and the current input.
The above mentioned circuit can be designed as a two-state Mealy machine. The states in the Mealy machine can be represented using Boolean values 0 and 1. We denote the current state, the next state, the next incoming bit, and the output bit of the Mealy machine by the variables s, t, b and y respectively.
Assume the initial state of the Mealy machine is 0.
What are the Boolean expressions corresponding to t and y in terms of s and b?
A Mealy Machine is a state machine where both the next state and the output are functions of the present state and the current input.
The above mentioned circuit can be designed as a two-state Mealy machine. The states in the Mealy machine can be represented using Boolean values 0 and 1. We denote the current state, the next state, the next incoming bit, and the output bit of the Mealy machine by the variables s, t, b and y respectively.
Assume the initial state of the Mealy machine is 0.
What are the Boolean expressions corresponding to t and y in terms of s and b?
Answer: (B)
The state stores the previous bit, so the next state is just the present input bit: t = b.
The output is 1 only when a 1 is not the first 1 of a run. That means the current bit is 1 and the previous bit was also 1: y = sb.
Check with 0011: the outputs are 0, 0, 0, 1. This is correct.
Answer: t = b, y = sb
The output is 1 only when a 1 is not the first 1 of a run. That means the current bit is 1 and the previous bit was also 1: y = sb.
Check with 0011: the outputs are 0, 0, 0, 1. This is correct.
Answer: t = b, y = sb
In an examination, a student can choose the order in which two questions (QuesA and QuesB) must be attempted.
If the first question is answered wrong, the student gets zero marks.
If the first question is answered correctly and the second question is not answered correctly, the student gets the marks only for the first question.
If both the questions are answered correctly, the student gets the sum of the marks of the two questions.
The following table shows the probability of correctly answering a question and the marks of the question respectively.
Assuming that the student always wants to maximize her expected marks in the examination, in which order should she attempt the questions and what is the expected marks for that order (assume that the questions are independent)?
If the first question is answered wrong, the student gets zero marks.
If the first question is answered correctly and the second question is not answered correctly, the student gets the marks only for the first question.
If both the questions are answered correctly, the student gets the sum of the marks of the two questions.
The following table shows the probability of correctly answering a question and the marks of the question respectively.
Assuming that the student always wants to maximize her expected marks in the examination, in which order should she attempt the questions and what is the expected marks for that order (assume that the questions are independent)?
Answer: (D)
Let us check both orders:
- If A is attempted first:
- If B is attempted first:
Attempting A first gives the higher value.
Answer: First QuesA and then QuesB. Expected marks 16
- If A is attempted first:
- If B is attempted first:
Attempting A first gives the higher value.
Answer: First QuesA and then QuesB. Expected marks 16
Consider the following ANSI C code segment:
z=x + 3 + y-> f1 + y-> f2;
for (i = 0; i < 200; i = i + 2)
{
if (z > i)
{
p = p + x + 3;
q = q + y-> f1;
} else
{
p = p + y-> f2;
q = q + x + 3;
}
}Assume that the variable y points to a struct (allocated on the heap) containing two fields f1 and f2, and the local variables x, y, z, p, q, and i are allotted registers. Common sub-expression elimination (CSE) optimization is applied on the code. The number of addition and the dereference operations (of the form y -> f1 or y -> f2) in the optimized code, respectively, are:Answer: (D)
CSE finds x + 3, yf1 and yf2 one time before the loop and reuses them.
- Before the loop: t = x + 3, then z = t + f1 + f2 3 additions, 2 dereferences.
- Loop: 100 passes (i = 0, 2, , 198). Each pass has i + 2, one addition to p, one to q 3 additions 100 = 300.
Total: 303 additions, 2 dereferences.
Answer: 303 and 2
- Before the loop: t = x + 3, then z = t + f1 + f2 3 additions, 2 dereferences.
- Loop: 100 passes (i = 0, 2, , 198). Each pass has i + 2, one addition to p, one to q 3 additions 100 = 300.
Total: 303 additions, 2 dereferences.
Answer: 303 and 2
The relation scheme given below is used to store information about the employees of a company, where empId is the key and deptId indicates the department to which the employee is assigned. Each employee is assigned to exactly one department.
Consider the following SQL query:
Consider the following SQL query:
select deptId, count(*)
from emp
where gender = "female" and salary > (select avg(salary)from emp)
group by deptId;The above query gives, for each department in the company, the number of female employees whose salary is greater than the average salary ofAnswer: (B)
The inner query (select avg(salary) from emp) has no where condition. It is also not correlated with the outer query. So it gives the average salary of all employees in the company.
Answer: employees in the company
Answer: employees in the company