GATE 2021 (Session 1)
65 questions
MCQ 34 · MSQ 13 · NAT 181-mark 30 · 2-mark 35
Questions 56–60 of 65
Consider the following pseudocode, where S is a semaphore initialized to 5 in line #2 and counter is a shared variable initialized to 0 in line #1. Assume that the increment operation in line #7 is not atomic.
1. int counter =0;
2. Semaphore S= init(5);
3. void parop(void)
4. {
5. wait(S);
6. wait(S);
7. counter++;
8. signal(S);
9. signal(S);
10. } If five threads execute the function concurrently, which of the following program behavior(s) is/are possible?One or more options are correct.
Answer: (A), (B), (D)
Every thread takes 2 of the 5 permits, so at most 2 threads can be inside at the same time. Also, counter++ is not atomic (read, add, write).
- (A) 5 is possible: the threads run one after another.
- (B) 1 is possible: thread T1 reads 0 and is preempted. The other four threads then run one at a time and counter becomes 4. After that, T1 writes .
- (C) 0 is impossible: every thread writes (value it read) + 1, which is at least 1, so counter can never be 0 at the end.
- (D) Deadlock is possible: all 5 threads do their first wait (S becomes 0), and then all of them block on the second wait.
Answer: (A), (B), (D)
- (A) 5 is possible: the threads run one after another.
- (B) 1 is possible: thread T1 reads 0 and is preempted. The other four threads then run one at a time and counter becomes 4. After that, T1 writes .
- (C) 0 is impossible: every thread writes (value it read) + 1, which is at least 1, so counter can never be 0 at the end.
- (D) Deadlock is possible: all 5 threads do their first wait (S becomes 0), and then all of them block on the second wait.
Answer: (A), (B), (D)
Consider a dynamic hashing approach for 4-bit integer keys:
1. There is a main hash table of size 4.
2. The 2 least significant bits of a key is used to index into the main hash table.
3. Initially, the main hash table entries are empty.
4. Thereafter, when more keys are hashed into it, to resolve collisions, the set of all keys corresponding to a main hash table. entry is organized as a binary tree that grows on demand.
5. First, the 3rd least significant bit is used to divide the keys into left and right subtrees.
6. To resolve more collisions, each node of the binary tree is further sub-divided into left and right subtrees based on the 4th least significant bit.
7. A split is done only if it is needed, i.e., only when there is a collision.
Consider the following state of the hash table.
Which of the following sequences of key insertions can cause the above state of the hash table (assume the keys are in decimal notation)?
1. There is a main hash table of size 4.
2. The 2 least significant bits of a key is used to index into the main hash table.
3. Initially, the main hash table entries are empty.
4. Thereafter, when more keys are hashed into it, to resolve collisions, the set of all keys corresponding to a main hash table. entry is organized as a binary tree that grows on demand.
5. First, the 3rd least significant bit is used to divide the keys into left and right subtrees.
6. To resolve more collisions, each node of the binary tree is further sub-divided into left and right subtrees based on the 4th least significant bit.
7. A split is done only if it is needed, i.e., only when there is a collision.
Consider the following state of the hash table.
Which of the following sequences of key insertions can cause the above state of the hash table (assume the keys are in decimal notation)?
One or more options are correct.
Answer: (C)
State of the table: index 00 is empty. Index 01 has 3 keys: one with 3rd bit 0, and two with 3rd bit 1 that split on the 4th bit. Index 10 has 2 keys, with 3rd bit 0 and 1. Index 11 has 1 key.
Option C: 10, 9, 6, 7, 5, 13
- 10 = 1010 10, bit3 = 0; 6 = 0110 10, bit3 = 1. True
- 9 = 1001 01, bit3 = 0; 5 = 0101 and 13 = 1101 01, bit3 = 1, split on bit4 (0 and 1). True
- 7 = 0111 11. True
The others fail: (A) puts 4 index 00; (B) has 1 and 9 colliding with bit3 = 0; (D) has 6 and 14 colliding and nothing in 11.
Answer: 10, 9, 6, 7, 5, 13
Option C: 10, 9, 6, 7, 5, 13
- 10 = 1010 10, bit3 = 0; 6 = 0110 10, bit3 = 1. True
- 9 = 1001 01, bit3 = 0; 5 = 0101 and 13 = 1101 01, bit3 = 1, split on bit4 (0 and 1). True
- 7 = 0111 11. True
The others fail: (A) puts 4 index 00; (B) has 1 and 9 colliding with bit3 = 0; (D) has 6 and 14 colliding and nothing in 11.
Answer: 10, 9, 6, 7, 5, 13
Consider the following ANSI C function:
int SimpleFunction(int Y[], int n, int x)
{
int total = Y[0], loopIndex;
for (loopIndex=1; loopIndex<=n-1; loopIndex++)
total=x*total +Y[loopIndex];
return total;
} Let Z be an array of 10 elements with Z[i]=1, for all i such that . The value returned by SimpleFunction(Z,10,2) is __________Answer: 1023
This function uses Horner's rule. It finds the value of .
Now take Y[i] = 1 for every i, x = 2 and n = 10:
Answer: 1023
Now take Y[i] = 1 for every i, x = 2 and n = 10:
Answer: 1023
Consider the sliding window flow-control protocol operating between a sender and a receiver over a full-duplex error-free link. Assume the following:
The time taken for processing the data frame by the receiver is negligible.
The time taken for processing the acknowledgement frame by the sender is negligible.
The sender has infinite number of frames available for transmission.
The size of the data frame is 2,000 bits and the size of the acknowledgement frame is 10 bits.
The link data rate in each direction is 1 Mbps ( bits per second).
One way propagation delay of the link is 100 milliseconds.
The minimum value of the sender's window size in terms of the number of frames, (rounded to the nearest integer) needed to achieve a link utilization of 50% is _____________
The time taken for processing the data frame by the receiver is negligible.
The time taken for processing the acknowledgement frame by the sender is negligible.
The sender has infinite number of frames available for transmission.
The size of the data frame is 2,000 bits and the size of the acknowledgement frame is 10 bits.
The link data rate in each direction is 1 Mbps ( bits per second).
One way propagation delay of the link is 100 milliseconds.
The minimum value of the sender's window size in terms of the number of frames, (rounded to the nearest integer) needed to achieve a link utilization of 50% is _____________
Answer: 50 to 52
Step by step:
- Time to send one data frame = 2000 / = 2 ms
- Time to send one ACK = 10 / = 0.01 ms
- Total cycle time = 2 + 100 + 0.01 + 100 = 202.01 ms
Link utilization: so the window is about 51 frames.
Answer: 51
- Time to send one data frame = 2000 / = 2 ms
- Time to send one ACK = 10 / = 0.01 ms
- Total cycle time = 2 + 100 + 0.01 + 100 = 202.01 ms
Link utilization: so the window is about 51 frames.
Answer: 51
Consider the following C code segment:
a = b + c;
e = a + 1;
d = b + c;
f = d + 1;
g = e + f;
In a compiler, this code segment is represented internally as a directed acyclic graph (DAG). The number of nodes in the DAG is _____________
a = b + c;
e = a + 1;
d = b + c;
f = d + 1;
g = e + f;
In a compiler, this code segment is represented internally as a directed acyclic graph (DAG). The number of nodes in the DAG is _____________
Answer: 6
Nodes that compute the same value are shared in the DAG:
- Leaves: b, c and 1, which is 3 nodes.
- b + c is used by both a and d so it is 1 node.
- (b + c) + 1 is used by both e and f so it is 1 node.
- e + f is 1 node.
Total = 6
Answer: 6
- Leaves: b, c and 1, which is 3 nodes.
- b + c is used by both a and d so it is 1 node.
- (b + c) + 1 is used by both e and f so it is 1 node.
- e + f is 1 node.
Total = 6
Answer: 6