PREVIOUS YEAR SOLVED PAPERS - GATE 2017 Shift 1

26. Consider the following functions from positive integers to real numbers:
10, √n, n, log2n, 100/n
The CORRECT arrangement of the above functions in increasing order of asymptotic complexity is:

  • Option : B
  • Explanation :
    As n → ∞, 100/n < 10 < log2n < √n < n
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *


27. Let T be a binary search tree with 15 nodes. The minimum and maximum possible heights of T are:
Note: The height of a tree with a single node is 0.

  • Option : B
  • Explanation :

    Min height = floor(log2N) = floor(log215)=3
    Max height n-1 = 14, when the tree is either left skewed or right skewed.
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *


28. Consider the following C code:
# include
int * assignval (int *x, int val) {
*x = val;
return x;
}
void main ( ) {
int * x= malloc (sizeof (int));
if (NULL = = x) return;
x = assignval (x,0);
if(x) {
x=(int *) malloc (sizeof (int));
if (NULL = = x) return;
x = assignval (x, 10);
}
printf(“%d\n”, *x);
free (x);
}
The code suffers from which one of the following problems:

  • Option : D
  • Explanation :
    A) is wrong. We don’t need to cast the result as void * is automatically and safely promoted to any other pointer type in this case.
    B) It is discarded for obvious reason.
    C) is wrong, because dangling pointer is nothing but the pointer which is pointing existing memory (deallocated or deleted memory) which is not happening here.
    D) is the answer. When you are calling malloc second time, new location is assigned to x and previous memory location is lost and now we don’t have no reference to that location resulting in memory leak.
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *


29. Consider a combination of T and D flip flip-flop is connected to the input of the D flip-flop is connected to the input of the T flip-flop and the output of the T Flip-flop is connected to the input of the D Flip-flop,

  • Option : B
  • Explanation :
       
    CLKQ1Q0
    011
    101
    210
    311
    401

    After 3rd clock pulse :11
    After 4th clock pulse: 01
    Qt can be observed from the diagram that :
    Q0 Q1 after the 3rd cycle are 11 and after the 4th cycle are 01
    Therefore, option B is correct
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *


30. Consider the C functions foo and bar given below:
int foo (int val ) {
int x = 0;
while (val > 0) {
x = x + foo ( val --);
}
return val ;
}
int bar (int val ) {
int x = 0;
while (val > 0) {
x = x + bar (val – 1) ;
}
return val ;
}
Invocations of foo (3) and bar (3) will result in:

  • Option : C
  • Explanation :
    In given function foo every time in the while foo is called value 3 because val is passed with post decrement operator so the value 3 is passed and val is decremented later. Every time the function is called a new variable is created as the passed variable is passed by value, with the value 3. So the function will close abruptly without returning any value.
    In the function bar, in the while loop value the value of val variable is not decrementing, it remains 3 only. Bar function in the while loop is called with val-1 i.e 2 but value of val is not decremented, so it will result in infinite loop.
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *


Related Quiz.
GATE 2017 Shift 1