# GATE-CS-2003

• Last Updated : 02 Dec, 2021

 Question 1
Consider the following C function.
float f(float x, int y)
{
float p, s; int i;
for (s=1, p=1, i=1; i < y; i ++)
{
p*= x/i;
s+=p;
}
return s;
}

For large values of y, the return value of the function f best approximates
 x^y e^x ln(1 + x) x^x

 Question 2
Assume the following C variable declaration
 int *A [10], B[10][10];

Of the following expressions I A[2] II A[2][3] III B[1] IV B[2][3] which will not give compile-time errors if used as left hand sides of assignment statements in a C program?
 I, II, and IV only II, III, and IV only II and IV only IV only

Question 2-Explanation:
 Question 3
Let P(E) denote the probability of the event E. Given P(A) = 1, P(B) = 1/2, the values of P(A | B) and P(B | A) respectively are
 1/4, 1/2 1/2, 1/14 1/2, 1 1, 1/2

Question 3-Explanation:
Given, , We need to find the conditional probability of two given events without being told about . Also it is not mentioned that they are independent events. But since is 1, it means that covers the complete sample space. So,
 Question 4

Let A be a sequence of 8 distinct integers sorted in ascending order. How many distinct pairs of sequences, B and C are there such that (i) each is sorted in ascending order, (ii) B has 5 and C has 3 elements, and (iii) the result of merging B and C gives A?

 256 56 30 2

Question 4-Explanation:

Suppose you have selected 3 elements from 8 in 8C3 ways, the remaining elements are treated as another array and merging both the arrays gives the sorted array. Here, you can select either 3 or 5.

=> 8C3 = 8C5 = 8!/(3!5!) = 7*8 = 56 Ways.

 Question 5
n couples are invited to a party with the condition that every husband should be accompanied by his wife. However, a wife need not be accompanied by her husband. The number of different gatherings possible at the party is
 A B C D

Question 5-Explanation:
There are three options for every couple.
1) Nobody goes to gathering
2) Wife alone goes
2) Both go
Since there are n couples, total possible ways of gathering are 3n
 Question 6
Let T(n) be the number of different binary search trees on n distinct elements. Then , where x is
 n-k+1 n-k n-k-1 n-k-2

Question 6-Explanation:
The idea is to make a key root, put (k-1) keys in one subtree and remaining n-k keys in other subtree. A Binary Search Tree (BST) is a tree in which all the nodes follow the below-mentioned properties −
• The left sub-tree of a node has a key less than or equal to its parent node's key.
• The right sub-tree of a node has a key greater than to its parent node's key.
Now construction binary search trees from n distinct number- Lets for simplicity consider n distinct numbers as first n natural numbers (starting from 1) If n=1 We have only one possibility, therefore only 1 BST. If n=2 We have 2 possibilities , when smaller number is root and bigger number is the right child or second when the bigger number is root and smaller number as left child.   If n=3 We have 5 possibilities. Keeping each number first as root and then arranging the remaining 2 numbers as in case of n=2.   If n=4 We have 14 possibilities. Taking each number as root and arranging smaal numbers as left subtree and larger numbers as right subtree. Thus we can conclude that with n distinct numbers, if we take ‘k’ as root then all the numbers smaller than k will left subtree and numbers larger than k will be right subtree where the the right subtree and left subtree will again be constructed recursively like the root. Therefore,   This solution is contributed by Parul Sharma.
 Question 7
Consider the set ∑* of all strings over the alphabet ∑ = {0, 1}. ∑* with the concatenation operator for strings
 does not form a group forms a non-commutative group does not have a right identity element forms a group if the empty string is removed from ∑*

Question 7-Explanation:
The given set with the concatenation operator forms a Monoid as it follows the properties of Closure, Associativity and has an identity element(null string). It is not a Group since no element has an inverse element i.e. there is no string S for another string R such that S*R = null string.
 Question 8
Let G be an arbitrary graph with n nodes and k components. If a vertex is removed from G, the number of components in the resultant graph must necessarily lie between
 k and n k - 1 and k + 1 k - 1 and n - 1 k + 1 and n - k

Question 8-Explanation:
Minimum: The removed vertex itself is a separate connected component. So removal of a vertex creates k-1 components. Maximum: It may be possible that the removed vertex disconnects all components. For example the removed vertex is center of a star. So removal creates n-1 components.
 Question 9
Assuming all numbers are in 2's complement representation, which of the following numbers is divisible by 11111011?
 11100111 11100100 11010111 11011011

Question 9-Explanation:
Since most significant bit is 1, all numbers are negative. 2's complement of divisor (11111011) = 1's complement + 1 = 00000100 + 1 = 00000101 So the given number is -5 The decimal value of option A is -25
 Question 10
For a pipelined CPU with a single ALU, consider the following situations
1. The j + 1-st instruction uses the result of the j-th instruction
as an operand
2. The execution of a conditional jump instruction
3. The j-th and j + 1-st instructions require the ALU at the same
time
Which of the above can cause a hazard ?
 1 and 2 only 2 and 3 only 3 only All of above

Question 10-Explanation:
Case 1: Is of data dependency .this can’t be safe with single ALU so read after write. Case 2:Conditional jumps are always hazardous they create conditional dependency in pipeline. Case 3:This is write after read problem or concurrency dependency so hazardous All the three are hazardous So (D) is correct option.
There are 89 questions to complete.