GATE CS 2021 | Set 2

Last Updated :
Discuss
Comments

Question 1

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 _________ .

  • 60

  • 10

  • 15

  • 50

Question 2

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:
 

  • 403 and 102

  • 203 and 2

  • 303 and 102

  • 303 and 2

Question 3

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?

  • 14

  • 20

  • 24

  • 30

Question 4

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 __________ .

  • 15

  • 1275

  • 30

  • 255

Question 5

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?
 

  • Lexical analyzer
     

  • Syntax analyzer
     

  • Semantic analyzer
     

  • Machine dependent optimizer
     

Question 6

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

  • 101

  • 110

  • 100

  • 111

Question 7

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 ______________ .

  • 130 to 140

  • 140 to 150

  • 120 to 130

  • 100 to 110

Question 8

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

  • For any two letters, the code assigned to one letter must not be a prefix of the code assigned to the other letter.
  • For any two letters of the same frequency, the letter which occurs earlier in the dictionary order is assigned a code whose length is at most the length of the code assigned to the other letter.

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

  • 21

  • 23

  • 25

  • 30

Question 9

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?

  • Θ(1)

  • Θ(logn)

  • Θ(n)

  • Θ(nlogn)

Question 10

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)?

  • A

  • B

  • C

  • D

Tags:

There are 65 questions to complete.

Take a part in the ongoing discussion