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

GATE 2006

191 questions

MCQ 1911-mark 191

Questions 96–100 of 191

Q96Array and Pointer1 markMCQ−0.33 if wrong
Consider the C code to swap two integers and these five statements: the code
 void swap(int *px,int *py){
*px=*px-*py;
*py=*px+*py;
*px=*py-*px;
}
S1 : will generate a compilation error
S2 : may generate a segmentation fault at runtime depending on the arguments passed
S3 : correctly implements the swap procedure for all input pointers referreing to integers stored in memory locations accessible tot he process
S4 : implements the swap procedure correctly for some but not all valid input pointers
S5 : may add or subtract integers and pointers

Q97Array1 markMCQ−0.33 if wrong
Given two arrays of numbers a1,...,ana_{1},...,a_{n} and b1,...,bnb_{1},...,b_{n} where each number is 0 or 1, the fastest algorithm to find the largest span(i,j) such that ai+ai+1+...+aj=bi+bi+1+.....+bja_{i}+a_{i+1}+...+a_{j}=b_{i}+b_{i+1}+.....+b_{j} , or report that there is no such span,

Q98Array1 markMCQ−0.33 if wrong
An element in an array X is called a leader if it is greater than all elements to the right of it in X. The best algorithm to find all leaders in an array.

Q99Queue1 markMCQ−0.33 if wrong
An implementation of a queue Q, using two stacks S1 and S2, is given below:

void insert(Q,x){
    push (S1,x);
}
void delete(Q){
   if (stack-empty (S2))then
         if (stack-empty (S1))then{
               print("Q is empty");
               return;
           }
         else while (! (stack-empty)(S1)){
                x=pop(S1);
                push(S2,x);
            }
       x=pop(S2);
}
Let n insert and m(≤\leqn) delete operations be performed in an arbitrary on an empty queue Q, Let x and y be the number of push and pop operations performed respectively in the processes. Which one of the following is true for all m and n ?

Q100Binary Tree1 markMCQ−0.33 if wrong
An array X of n distinct integers is interpreted as a complete binary tree. The index of the first element of the array is 0. If the root node is at level 0, the level of element X[i],i≠0X[i], i \neq 0, is