GATE 2008
185 questions
MCQ 1851-mark 52 · 2-mark 133
Questions 96–100 of 185
Answer: (B)
Batch method: copy the new elements to the end of the array (one write each, so work). Then run Build-Heap on the whole array of elements.
Build-Heap sifts down every internal node. A node at height costs , and about nodes have height . The total is , because the sum equals 2.
So the upper bound is . Every new element must be handled at least once, so the lower bound is . Together the time is .
Doing separate inserts at each gives , but that is only the cost of the slower method, not the best possible time.
Answer: (B)
Answer: (C)
In a B-tree of order 4, a node holds at most 3 keys. When a 4th key arrives, the node splits: the middle key goes up to the parent and the other keys form two nodes. If the parent then overflows, it splits too.
Take keys inserted in ascending order, . This leaves half-empty nodes behind and forces splits as often as possible.
Inserting 1, 2, 3 fills one node. Then:
Key 4: the node splits, 2 goes up (split 1).
Key 5: the right leaf has room, no split.
Key 6: the right leaf [3, 4, 5] overflows and splits, 4 goes up (split 2).
Key 7: no split.
Key 8: the leaf [5, 6, 7] overflows and splits, 6 goes up (split 3).
Key 9: it goes into the leaf [7, 8], which has room, so no split.
Key 10: the leaf [7, 8, 9] overflows and splits, 8 goes up (split 4). The parent [2, 4, 6, 8] now has 4 keys, so it splits too, 4 becomes the new root (split 5).
Why 5 is the most: every leaf has at least 1 key, and each leaf split adds one leaf and puts one key in the internal level. With leaf splits there are leaves and internal keys, so , which gives . An internal split needs a node with 4 internal keys, so it can happen only when , and only once. So the splits are at most .
Answer: (C)
43 36 92 87 11 4 71 13 14
is inserted into an initially empty hash table, the bins of which are indexed from zero to ten. What is the index of the bin into which the last record is inserted?
Answer: (D)
With and linear probing (try the next slot, wrapping from 10 to 0):
- 43: , so slot 10.
- 36: 3, so slot 3.
- 92: 4, so slot 4.
- 87: 10 is full, so slot 0.
- 11: 0 is full, so slot 1.
- 4: 4 is full, so slot 5.
- 71: is full, so slot 6.
- 13: , so slot 2.
- 14: . Slots 3, 4, 5 and 6 are full, so slot 7.
Final hash table:
Answer: (D)
Answer: (C)
The keys are less than , so a key has at most binary digits. The keys are also more than , so the largest key has at least digits. So . Since is a constant independent of , it drops out and .
Time . The lower bound on the range is what makes this tight () and not only an upper bound.
Option B, , would need only about passes. That happens only if the digit base itself grows with (base ). With a fixed base, the number of digits grows as , so (C) is the answer.
Answer: (C)
Answer: (B)
Sorting the two parts costs . Partitioning compares every other element with the pivot, which is at most comparisons. So
.
(A) is wrong: its parts and cover only elements, so most of the list is not sorted. (C) charges to both parts, but the two parts together hold only elements, so it is not the recurrence of this split. (D) assumes an exactly even split, which this pivot rule does not guarantee.
Answer: (B)