GATE 2016 (Session 1)
65 questions
MCQ 39 · NAT 261-mark 30 · 2-mark 35
Questions 56–60 of 65
Consider the following Syntax Directed Translation Scheme(SDTS),with non-terminals {S, A} and terminals {a, b}.
S aA {print 1}
S a { print 2}
A Sb { print 3}
Using the above SDTS, the output printed by a bottom-up parser, for the input aab is:
S aA {print 1}
S a { print 2}
A Sb { print 3}
Using the above SDTS, the output printed by a bottom-up parser, for the input aab is:
Answer: (C)
A bottom-up parser prints at each reduction. Parse with the rules {print 1}, {print 2}, {print 3}:
1. Shift , shift . Reduce the second by : output 2.
2. Shift . Reduce by : output 3.
3. Reduce by : output 1.
The output is 231.
Answer: (C)
1. Shift , shift . Reduce the second by : output 2.
2. Shift . Reduce by : output 3.
3. Reduce by : output 1.
The output is 231.
Answer: (C)
Consider a computer system with 40-bit virtual addressing and page size of sixteen kilobytes. If the computer system has a one level page table per process and each page table entry requires 48 bits, then the size of the per-process page table is _________ mega bytes.
Answer: 384
Number of page table entries: . Every entry takes 48 bits, which is 6 bytes.
Page table size: MB
Answer: 384
Page table size: MB
Answer: 384
Consider a disk queue with requests for I/O to blocks on cylinders 47,38,121,191,87,11, 92, 10. The C-LOOK scheduling algorithm is used. The head is initially at cylinder number 63, moving to wards larger cylinder numbers on its servicing pass. The cylinders are numbered from 0to 199. The total head movement (in number of cylinders) incurred while servicing these requests is____ .
Answer: 346
Start at 63 and move up: serve 87, 92, 121, 191. This movement is 191 63 = 128. Then jump to the lowest request 10, which costs 191 10 = 181. Then serve 11, 38, 47, which costs 47 10 = 37.
Total = 128 + 181 + 37 = 346
Answer: 346
Total = 128 + 181 + 37 = 346
Answer: 346
Consider a computer system with ten physical page frames. The system is provided with an access sequence , where each is a distinct virtual page number. The difference in the number of page faults between the last-in-first-out page replacement policy and the optimal page replacement policy is ______.
Answer: 1
With 10 frames, the first pass over a1 to a20 has 20 faults for every policy, because all the pages are new.
LIFO: a1 to a10 fill the frames. Each of a11 to a20 then replaces the page loaded last (a11 replaces a10, a12 replaces a11, and so on). After the first pass the frames hold a1 to a9 and a20. In the second pass, a1 to a9 are hits. a10 faults and replaces a20 (the last page loaded), and each of a11 to a20 faults and replaces the one before it. That is 11 faults (a10 to a20). Total = 20 + 11 = 31.
Optimal: In the first pass, a11 replaces a10, which is needed farthest in the future, a12 replaces a11, and so on. So the frames also end the first pass holding a1 to a9 and a20. In the second pass, a1 to a9 are hits. a10 faults and replaces a page that is never needed again (one of a1 to a9). a11 to a19 fault in the same way, each replacing a page that is never needed again. a20 is still in memory, so it is a hit. That is 10 faults (a10 to a19). Total = 20 + 10 = 30.
Difference = 31 30 = 1
Answer: 1
LIFO: a1 to a10 fill the frames. Each of a11 to a20 then replaces the page loaded last (a11 replaces a10, a12 replaces a11, and so on). After the first pass the frames hold a1 to a9 and a20. In the second pass, a1 to a9 are hits. a10 faults and replaces a20 (the last page loaded), and each of a11 to a20 faults and replaces the one before it. That is 11 faults (a10 to a20). Total = 20 + 11 = 31.
Optimal: In the first pass, a11 replaces a10, which is needed farthest in the future, a12 replaces a11, and so on. So the frames also end the first pass holding a1 to a9 and a20. In the second pass, a1 to a9 are hits. a10 faults and replaces a page that is never needed again (one of a1 to a9). a11 to a19 fault in the same way, each replacing a page that is never needed again. a20 is still in memory, so it is a hit. That is 10 faults (a10 to a19). Total = 20 + 10 = 30.
Difference = 31 30 = 1
Answer: 1
Consider the following proposed solution for the critical section problem. There are n processes: . In the code,function returns an integer not smaller than any of its arguments. For all i, t[i] is initialized to zero.
Code for Pi:
Which one of the following is TRUE about the above solution?
Code for Pi:
do {
c[i]=1; t[i] = pmax(t[0],...,t[n-1])+1; c[i]=0;
for every j ≠ i in {0,...,n-1} {
while (c[j]);
while (t[j] != 0 && t[j]<=t[i]);
}
Critical Section;
t[i]=0;
Remainder Section;
} while (true); Which one of the following is TRUE about the above solution?
Answer: (A)
This is a bakery-style algorithm. A process takes a ticket t[i] while its c[i] is 1, and every other process waits while c[j] is 1. So when Pi compares tickets, the ticket of every other process is final. Pi then enters only when each other process has ticket 0 or a larger ticket. Any process that takes a ticket later reads t[i] in pmax and gets a larger one, so it waits for Pi. Two processes cannot both pass, so mutual exclusion holds.
However, two processes that run pmax at the same time can take the same ticket, because pmax is not atomic. Then each one waits for the other, since the test t[j] t[i] is true in both directions. This is a deadlock, so progress and bounded waiting also fail, and (D) is false.
Answer: (A)
However, two processes that run pmax at the same time can take the same ticket, because pmax is not atomic. Then each one waits for the other, since the test t[j] t[i] is true in both directions. This is a deadlock, so progress and bounded waiting also fail, and (D) is false.
Answer: (A)