GATE 2007 Computer Science and Information Technology (CS) Questions with Solutions

GATE 2007

184 questions

MCQ 1841-mark 184

Questions 76–80 of 184

Q76Array1 markMCQ−0.33 if wrong
An array of n numbers is given, where n is an even number. The maximum as well as the minimum of these n numbers needs to be determined. Which of the following is TRUE about the number of comparisons needed?

Q77Stack1 markMCQ−0.33 if wrong
Consider the following C program:
 #include < stdio.h >

           #define EOF -1
           void push (int); /* push the argument on the stack */
           int pop  (void); /* pop the top of the stack */
           void flagError ();
           int main ()
          {         int c, m, n, r;
                     while ((c = getchar ()) != EOF)
                    { if  (isdigit (c) )
                               push (c);
                     else if ((c == '+') || (c == '*'))
                    {          m = pop ();
                                n = pop ();
                                r = (c == '+') ? n + m : n*m;
                                push (r);
                      }
                      else if (c != ' ')
                               flagError ();
             }
              printf("% c", pop ());
}

What is the output of the program for the following input?
5 2 * 3 3 2 + * +

Q78Stack1 markMCQ−0.33 if wrong
The following postfix expression with single digit operands is evaluated using a stack:

8 2 3 ^ / 2 3 * + 5 1 * -  
Note that ^ is the exponentiation operator. The top two elements of the stack after the first * is evaluated are:

Q79Queue1 markMCQ−0.33 if wrong
Suppose you are given an implementation of a queue of integers. The operations that can be performed on the queue are:
i. isEmpty(Q) returns true if the queue is empty, false otherwise.
ii. delete(Q) deletes the element at the front of the queue and returns its value.
iii. insert(Q,i) inserts the integer i at the rear of the queue.
Consider the following function
void f (queue Q) {
int i ;
if (!isEmpty(Q)) {
   i = delete(Q);
   f(Q);
   insert(Q, i);
  }
} 

What operation is performed by the above function f ?

Q80Binary Tree1 markMCQ−0.33 if wrong
Consider the following C program segment where CellNode represents a node in a binary tree:
 struct CellNode 
{
  struct CellNode *leftChild;
  int element;
  struct CellNode *rightChild;
};
 
int GetValue(struct CellNode *ptr) 
{
  int value = 0;
  if (ptr != NULL) 
  {
   if ((ptr->leftChild == NULL) &&
        (ptr->rightChild == NULL))
      value = 1;
   else
      value = value + GetValue(ptr->leftChild)
                   + GetValue(ptr->rightChild);
  }
  return(value);
}
The value returned by GetValue when a pointer to the root of a binary tree is passed as its argument is: