GATE 2021 (Session 1) Computer Science and Information Technology (CS) Questions with Solutions

GATE 2021 (Session 1)

65 questions

MCQ 34 · MSQ 13 · NAT 181-mark 30 · 2-mark 35

Questions 56–60 of 65

Q56Process Synchronization2 marksMSQ
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 paropparop concurrently, which of the following program behavior(s) is/are possible?

One or more options are correct.

Q57Hashing2 marksMSQ
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.
00 01 10 11 empty 0 1 0 1 0 1
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.

Q58Function2 marksNAT
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 0≤i≤90\leq i \leq 9. The value returned by SimpleFunction(Z,10,2) is __________

Q60Syntax-directed Translation2 marksNAT
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 _____________