GATE 2000
54 questions
MCQ 541-mark 54
Questions 31–35 of 54
for all
The sum of the elements of the array is
Answer: (A)
Split it: and . Both are the same number, , so the difference is .
Another way to see it: , so each entry cancels its mirror entry across the diagonal, and the diagonal entries are all . The table below shows this for .
Answer: (A)
Answer: (D)
Facts: in postorder the root is always visited last, so LASTPOST is the root. In inorder the last node is found by going right from the root as long as a right child exists. In preorder the last node is found by going to the right child if there is one, else to the left child, until a leaf is reached.
Take the tree with 3 nodes: root R, left child L, right child T. Postorder is L T R, inorder is L R T, preorder is R L T. So LASTPOST = R, LASTIN = T, LASTPRE = T. Then LASTIN is not LASTPOST (A is false) and LASTPRE is not LASTPOST (C is false).
Take the tree with 2 nodes: root R with only a left child L. Inorder is L R, so LASTIN = R. Preorder is R L, so LASTPRE = L. Then LASTIN is not LASTPRE (B is false).
So none of the three equalities always holds.
Answer: (D)
Answer: (C)
(A) The part (4 5 6 7) has four items, so it is not of the form (X Y Z). Invalid.
(B) (1 (2 3 4) 5 6) has four items, and the string ends with 7), which has a closing parenthesis that matches nothing. Invalid.
(C) (1 (2 3 4) (5 6 7)): node 1 has left subtree (2 3 4) and right subtree (5 6 7). Each of these is a node with two items after it, and the parentheses balance. Valid.
(D) (4 5) has only two items, with no right subtree given, so it is not of the form (X Y Z). It would be valid as (4 5 NULL). Invalid.
Note: the statement says Y and Z are NULL or nested groups, so a bare label such as 3 in (2 3 4) is strictly not covered. The key reads a bare label as a leaf node.
Answer: (C)
Which of the following is true?
Answer: (D)
Rewrite using :
So . The two functions differ only by the constant factor 3, so each one is of the other.
For , the top factors are each at least , so . Taking gives about , which is far more than for large . So grows faster than both and .
(A) h(n) is O(f(n)): false, grows faster.
(B) h(n) is O(g(n)): false, same reason.
(C) g(n) is not O(f(n)): false, because , so is .
(D) f(n) is O(g(n)): true, because .
Answer: (D)
Answer: (A)
S is sorted in ascending order: . For any two different elements and with , we have and . So the smallest possible pair sum is .
Some pair has sum less than 1000 exactly when . One addition and one comparison decide this, however large is, so . (If the array were sorted in descending order, the last two elements would be used instead.)
Options (B), (C) and (D) all say the time grows with , which is wrong.
Answer: (A)