GATE 2014 (Session 2)
65 questions
MCQ 42 · NAT 231-mark 30 · 2-mark 35
Questions 21–25 of 65
Suppose n and p are unsigned int variables in a C program. We wish to set p to . If n is large, which one of the following statements is most likely to set p correctly?
Answer: (B)
. In C, and are unsigned int, so every step is done in unsigned int, left to right, and integer division drops the fraction. We need a form with an exact division at each step and small intermediate values.
- (A) The product is computed first. For large it overflows before the division by 6.
- (B) is , always a whole number. Multiplying by gives , so the division by 3 is exact. The largest intermediate value is only half of that in (A), so it is right for a larger range of .
- (C) is not always whole. For : , then , and , but .
- (D) The product is still computed in unsigned int first, and overflows for large before the division by turns it into a double.
Answer: (B)
- (A) The product is computed first. For large it overflows before the division by 6.
- (B) is , always a whole number. Multiplying by gives , so the division by 3 is exact. The largest intermediate value is only half of that in (A), so it is right for a larger range of .
- (C) is not always whole. For : , then , and , but .
- (D) The product is still computed in unsigned int first, and overflows for large before the division by turns it into a double.
Answer: (B)
A priority queue is implemented as a Max-Heap. Initially, it has 5 elements. The level-order traversal of the heap is: 10, 8, 5, 3, 2. Two new elements 1 and 7 are inserted into the heap in that order. The level-order traversal of the heap after the insertion of the elements is:
Answer: (A)
Start with the heap: 10, 8, 5, 3, 2.
- Insert 1: it is placed as the left child of 5. Compare: 1 5, so no swap. Result 10, 8, 5, 3, 2, 1
- Insert 7: it is placed as the right child of 5. Compare: 7 5, so swap. Then 7 10, so stop. Result 10, 8, 7, 3, 2, 1, 5
Answer: (A) 10, 8, 7, 3, 2, 1, 5
- Insert 1: it is placed as the left child of 5. Compare: 1 5, so no swap. Result 10, 8, 5, 3, 2, 1
- Insert 7: it is placed as the right child of 5. Compare: 7 5, so swap. Then 7 10, so stop. Result 10, 8, 7, 3, 2, 1, 5
Answer: (A) 10, 8, 7, 3, 2, 1, 5
Which one of the following correctly determines the solution of the recurrence relation with T(1) = 1?
Answer: (A)
Use the Master theorem with a = 2 and b = 2. Then compute: .
Compare f(n): . So case 1 applies, and the result is: .
Final answer:
Compare f(n): . So case 1 applies, and the result is: .
Final answer:
Consider the tree arcs of a BFS traversal from a source node W in an unweighted, connected, undirected graph. The tree T formed by the tree arcs is a data structure for computing
Answer: (B)
In an unweighted graph, BFS starts at W and visits the vertices one level at a time. So the tree path from W to any vertex v uses the fewest possible edges.
The tree does not give the shortest paths between other pairs of vertices.
Answer: the shortest path from W to every vertex in the graph
The tree does not give the shortest paths between other pairs of vertices.
Answer: the shortest path from W to every vertex in the graph
If and , Consider
(I) is a regular language
(II)
Which one of the following is CORRECT?
(I) is a regular language
(II)
Which one of the following is CORRECT?
Answer: (A)
The concatenation is . This language is regular so (I) is true.
The number of a's and the number of b's do not depend on each other. So the language is not equal to (for example, aab is in it) so (II) is false.
Answer: Only (I)
The number of a's and the number of b's do not depend on each other. So the language is not equal to (for example, aab is in it) so (II) is false.
Answer: Only (I)