GATE CS 2012

Last Updated : 11 Oct, 2021

Question 1
Which of the followings is/are automatically added to every class, if we do not write our own.
Cross
Copy Constructor
Cross
Assignment Operator
Cross
A constructor without any parameter
Tick
All of the above


Question 1-Explanation: 
In C++, if we do not write our own, then compiler automatically creates a default constructor, a copy constructor and a assignment operator for every class.
Question 2

Consider the following code:

C++

int a, b, c = 0;

void prtFun(void);

void main()
{
    static int a = 1;
    prtFun();
    a += 1;
    prtFun() printf("n %d %d ", a, b);
}

void prtFun(void)
{
    static int a = 2;
    int b = 1;
    a += ++b;
    printf("n %d %d ", a, b);
}

What output will be generated by the given code d\segment if: 
Line 1 is replaced by “auto int a = 1;” 
Line 2 is replaced by “register int a = 2;” (GATE CS 2012) 

 

Cross

3 1

4 1

4 2

 

Cross

4 2

6 1

6 1

 

Cross

4 2

6 2

2 0

 

Tick

4 2

4 2

2 0

 



Question 2-Explanation: 

If we replace line 1 by “auto int a = 1;” and line 2 by “register int a = 2;”, then ‘a’ becomes non-static in prtFun(). The output of first prtFun() remains same. But, the output of second prtFun() call is changed as a new instance of ‘a’ is created in second call. So “4 2″ is printed again. Finally, the printf() in main will print “2 0″. Making ‘a’ a register variable won’t change anything in output. 

Please write comments if you find any of the answers/explanations incorrect, or you want to share more information about the topics discussed above.
 

Question 3
Consider the following logical inferences.
I1: If it rains then the cricket match will not be played.
The cricket match was played.
Inference: There was no rain.
I2: If it rains then the cricket match will not be played.
It did not rain.
Inference: The cricket match was played.
Which of the following is TRUE?
Cross
Both I1 and I2 are correct inferences
Tick
I1 is correct but I2 is not a correct inference
Cross
I1 is not correct but I2 is a correct inference
Cross
Both I1 and I2 are not correct inferences


Question 3-Explanation: 
The cricket match may not be played even if doesn\'t rain.
Question 4
Which of the following is TRUE?
Cross
Every relation in 3NF is also in BCNF
Cross
A relation R is in 3NF if every non-prime attribute of R is fully functionally dependent on every key of R
Tick
Every relation in BCNF is also in 3NF
Cross
No relation can be in both BCNF and 3NF


Question 4-Explanation: 

BCNF is a stronger version 3NF. So every relation in BCNF will also be in 3NF.

Question 5
What will be the output of the following C program segment?
char inchar = 'A';
switch (inchar)
{
case 'A' :
    printf ("choice A \n") ;
case 'B' :
    printf ("choice B ") ;
case 'C' :
case 'D' :
case 'E' :
default:
    printf ("No Choice") ;
}
Cross
No choice
Cross
Choice A
Tick
Choice A
Choice B No choice
Cross
Program gives no output as it is erroneous


Question 5-Explanation: 
There is no break statement in case ‘A’. If a case is executed and it doesn’t contain break, then all the subsequent cases are executed until a break statement is found. That is why everything inside the switch is printed. Try following program as an exercise.
int main()
{
    char inchar = \'A\';
    switch (inchar)
    {
    case \'A\' :
        printf (\"choice A \\n\") ;
    case \'B\' :
    {
        printf (\"choice B\") ;
        break;
    }
    case \'C\' :
    case \'D\' :
    case \'E\' :
    default:
        printf (\"No Choice\") ;
    }
}
Question 6
Assuming P != NP, which of the following is true ?
(A) NP-complete = NP
(B) NP-complete \cap P = \Phi
(C) NP-hard = NP
(D) P = NP-complete
Cross
A
Tick
B
Cross
C
Cross
D


Question 6-Explanation: 

The answer is B (no NP-Complete problem can be solved in polynomial time). Because, if one NP-Complete problem can be solved in polynomial time, then all NP problems can solved in polynomial time. If that is the case, then NP and P set become same which contradicts the given condition.

Related Article: NP-Completeness | Set 1 (Introduction) P versus NP problem (Wikipedia)
Question 7
The worst case running time to search for an element in a balanced in a binary search tree with n2^n elements is
(A) \\Theta(n log n)

(B) \\Theta (n2^n) 

(C) \\Theta (n) 

(D) \\Theta (log n)  
Cross
A
Cross
B
Tick
C
Cross
D


Question 7-Explanation: 
-> The search time in a binary search tree depends on the form of the tree, that is on the order in which its nodes were inserted. A pathological case: The n nodes were inserted by increasing order of the keys, yielding something like a linear list (but with a worse space consumption), with O(n) search time(in the case of skew tree). -> A balanced tree is a tree where every leaf is “not more than a certain distance” away from the root than any other leaf.So in balanced tree, the height of the tree is balanced to make distance between root and leafs nodes a low as possible. In a balanced tree, the height of tree is log2(n). -> So , if a Balanced Binary Search Tree contains n2n elements then Time complexity to search an item: Time Complexity = log(n2n) = log (n) + log(2n) = log (n) +n = O(n) So Answer is C. See http://www.geeksforgeeks.org/data-structures-and-algorithms-set-28/ This solution is contributed by Nirmal Bharadwaj
Question 8
The truth table truthtable represents the Boolean function
Tick
X
Cross
X+Y
Cross
X xor Y
Cross
Y


Question 8-Explanation: 
The value of f(X, Y) is same as X for all input pairs. Also sum of product form of expression we get,
= XY’+XY
= X(Y’+Y)
= X *1
= X 
We see from truth table –
Column x = f(x,y) 
So , 
f(x,y)=x 
Option (A) is correct.
Question 9
The decimal value 0.5 in IEEE single precision floating point representation has
Cross
fraction bits of 000…000 and exponent value of 0
Tick
fraction bits of 000…000 and exponent value of −1
Cross
fraction bits of 100…000 and exponent value of 0
Cross
no exact representation


Question 9-Explanation: 
The IEEE 754 standard specifies following distribution of bits: Sign bit: 1 bit Exponent width: 8 bits Significand or Fraction: 24 (23 explicitly stored) 0.5 in base 10 means 1 X 2-1 in base 2. So exponent bits have value -1 and all fraction bits are 0.
Question 10
A process executes the code
fork();
fork();
fork(); 
The total number of child processes created is
Cross
3
Cross
4
Tick
7
Cross
8


Question 10-Explanation: 
Let us put some label names for the three lines
  fork ();    // Line 1
  fork ();   // Line 2
  fork ();   // Line 3

       L1       // There will be 1 child process created by line 1
    /     \\
  L2      L2    // There will be 2 child processes created by line 2
 /  \\    /  \\
L3  L3  L3  L3  // There will be 4 child processes created by line 3
We can also use direct formula to get the number of child processes. With n fork statements, there are always 2^n – 1 child processes. Also see this post for more details.
There are 61 questions to complete.

Share your thoughts in the comments

Similar Reads