• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

GATE-CS-2004

Question 31

Consider the following program fragment for reversing the digits in a given integer to obtain a new integer. Let n = D1D2…Dm C
int n, rev;
rev = 0;
while (n > 0)
{
   rev = rev*10 + n%10;
   n = n/10;
}
The loop invariant condition at the end of the ith iteration is:
  • n = D1D2….Dm-i and rev = DmDm-1…Dm-i+1
  • n = Dm-i+1…Dm-1Dm and rev = Dm-1….D2D1
  • n != rev
  • n = D1D2….Dm and rev = DmDm-1…D2D1

Question 32

Consider the following C program segment:

C
char p[20];
char *s = \"string\";
int length = strlen(s);
int i;
for (i = 0; i < length; i++)
     p[i] = s[length  i];
printf(\"%s\",p);

The output of the program is (GATE CS 2004)

  • gnirts

  • gnirt

  • string

  • no output is printed

Question 33

Which of the following language supports polymorphism but not the classes?

  • Java

  • C++

  • Ada

  • C#

Question 34

Consider the label sequences obtained by the following pairs of traversals on a labeled binary tree. Which of these pairs identify a tree uniquely ?
(i)     preorder and postorder
(ii)    inorder and postorder
(iii)   preorder and inorder
(iv)   level order and postorder
  • (i) only
  • (ii), (iii)
  • (iii) only
  • (iv) only

Question 35

A circularly linked list is used to represent a Queue. A single variable p is used to access the Queue. To which node should p point such that both the operations enQueue and deQueue can be performed in constant time? circularLinkedList
  • rear node
  • front node
  • not possible with a single pointer
  • node next to front

Question 36

The elements 32, 15, 20, 30, 12, 25, 16 are inserted one by one in the given order into a Max Heap. The resultant Max Heap is. tree
  • a
  • b
  • c
  • d

Question 37

Assume that the operators +, -, × are left associative and ^ is right associative. The order of precedence (from highest to lowest) is ^, x , +, -. The postfix expression corresponding to the infix expression a + b × c - d ^ e ^ f is

  • abc × + def ^ ^ -

  • abc × + de ^ f ^ -

  • ab + c × d - e ^ f ^

  • - + a × bc ^ ^ def

Question 38

Two matrices M1 and M2 are to be stored in arrays A and B respectively. Each array can be stored either in row-major or column-major order in contiguous memory locations. The time complexity of an algorithm to compute M1 × M2 will be
  • best if A is in row-major, and B is in column- major order
  • best if both are in row-major order
  • best if both are in column-major order
  • independent of the storage scheme

Question 39

Suppose each set is represented as a linked list with elements in arbitrary order. Which of the operations among union, intersection, membership, cardinality will be the slowest?

  • union only

  • intersection, membership

  • membership, cardinality

  • union, intersection

Question 40

Consider the following C program C
main()
{
    int x, y, m, n;
    scanf (\"%d %d\", &x, &y);
    /* Assume x > 0 and y > 0  */
    m = x;
    n = y;
    while (m! = n)
    {
        if (m > n)
            m = m - n;
        else
            n = n - m;
    }
    print f (\"% d\", n);
}
The program computes
  • x ÷ y using repeated subtraction
  • x mod y using repeated subtraction
  • the greatest common divisor of x and y
  • the least common multiple of x and y

There are 90 questions to complete.

Last Updated :
Take a part in the ongoing discussion