GATE CS 2021 | Set 2 (original) (raw)

Consider the following ANSI C program

#include
int foo(int x, int y, int q)
{
if ((x<=0) && (y<=0))
return q;
if (x<=0)
return foo(x, y-q, q);
if (y<=0)
return foo(x-q, y, q);
return foo(x, y-q, q) + foo(x-q, y, q);
}
int main( )
{
int r = foo(15, 15, 10);
printf(“%d”, r);
return 0;
}

The output of the program upon execution is _________ .

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:

Consider the following ANSI C program.

#include < stdio.h >
int main( )
{
int arr[4][5];
int i, j;
for (i=0; i<4; i++)
{
for (j=0; j<5; j++)
{
arr[i][j] = 10 * i + j;
}
}
printf("%d", *(arr[1]+9));
return 0;
}

What is the output of the above program?

Consider the following ANSI C function:

int SomeFunction (int x, int y)
{
if ((x==1) || (y==1)) return 1;
if (x==y) return x;
if (x > y) return SomeFunction(x-y, y);
if (y > x) return SomeFunction (x, y-x);

}

The value returned by SomeFunction (15, 255) is __________ .

Consider the following ANSI C program:

int main () {
Integer x;
return 0;
}

Which one of the following phases in a seven-phase C compiler will throw an error?

Consider the cyclic redundancy check (CRC) based error detecting scheme having the generator polynomial X3+X+1. Suppose the message m4m3m2m1m0 = 11000 is to be transmitted. Check bits c2c1c0 are appended at the end of the message by the transmitter using the above CRC scheme. The transmitted bit string is denoted by m4m3m2m1m0c2c1c0. The value of the checkbit sequence c2c1c0 is

Consider a network using the pure ALOHA medium access control protocol, where each frame is of length 1,000 bits. The channel transmission rate is 1 Mbps (=106 bits per second). The aggregate number of transmissions across all the nodes (including new frame transmissions and retransmitted frames due to collisions) is modelled as a Poisson process with a rate of 1,000 frames per second. Throughput is defined as the average number of frames successfully transmitted per second. The throughput of the network (rounded to the nearest integer) is ______________ .

Consider the string abbccddeee. Each letter in the string must be assigned a binary code satisfying the following properties:

Among the set of all binary code assignments which satisfy the above two properties, what is the minimum length of the encoded string?

Let H be a binary min-heap consisting of n elements implemented as an array. What is the worst case time complexity of an optimal algorithm to find the maximum element in H?

For constants a≥1 and b>1, consider the following recurrence defined on the non-negative integers:

T(n) = a⋅T(n/b) + f(n)

Which one of the following options is correct about the recurrence T(n)?

There are 65 questions to complete.

Take a part in the ongoing discussion