GATE 2007
184 questions
MCQ 1841-mark 184
Questions 86–90 of 184
Answer: (B)
Because the heap is stored in an array, the parent of index is at , so any node of the path can be found directly from its index. That lets us do binary search on the path.
Binary search on sorted items takes comparisons. Here , so the number of comparisons is .
Answer: (B)
Keys K15 and then K25 are inserted into this tree in that order. Now the key K50 is deleted from the tree resulting after the two insertions made earlier. Consider the following statements about the tree resulting after this deletion.
i. The height of the tree remains the same.
ii. The node
(disregarding the links) is present in the tree.
iii. The root node remains unchanged (disregarding the links).
Which one of the following options is true ?
Answer: (A)
Insert K15: it goes to leaf [K10, K20], which becomes K10, K15, K20 (3 keys, but at most 2 are allowed). It splits into [K10] and [K15, K20], and K15 is copied up into the parent [K30], which becomes [K15, K30].
Insert K25: it goes to leaf [K15, K20] (K25 lies between K15 and K30), which splits into [K15] and [K20, K25]. K20 goes up, so the parent has K15, K20, K30 and splits too. K20 moves up to the root, which becomes [K20, K40]. The tree after both insertions is below. The circled nodes are the ones changed when K50 is deleted.
Delete K50: the leaf [K50] becomes empty. Its sibling leaf [K40] has only 1 key, the minimum, so it cannot lend one. The two leaves merge into [K40]. The parent node [K50] is left with one child and no key. The next figure shows this middle state, with [K40] hanging directly below the root, one level too high.
That internal node is too small, so it merges with its sibling [K30], which has only 2 children and cannot lend one. K40 comes down from the root, and the merged node is [K30, K40] with leaves [K20, K25], [K30], [K40]. The root loses K40 and becomes [K20]. This last step is a merge, not a redistribution.
(i) Height: the original tree and the final tree both have root, internal nodes and leaves, so the height is the same. True.
(ii) The node with the single key K20 is the new root. True.
(iii) The root was [K40] at the start, and is [K20] at the end. It changed. False.
Answer: (A)
Keys K15 and then K25 are inserted into this tree in that order. Exactly how many of the following nodes (disregarding the links) will be present in the tree after the two insertions?
Answer: (A)
Each node has at most two keys and three links. A leaf holds at most 2 keys; an overflow splits the leaf and copies the first key of the new right leaf up into the parent.
Insert first. It goes to the leaf , which is full. The leaf splits into and , and K15 is copied up. The parent becomes , which still fits. The tree becomes:
Next, insert . It lies between K15 and K30, so it goes to the leaf , which is full. That leaf splits into and , and K20 is copied up. The parent would now hold , which is too many, so it splits as well: K20 moves up into the root, leaving and . The root becomes . The tree becomes:
The listed nodes are , , and . In the final tree, only is present (the leaf existed after the first insertion but was split by the second). So exactly 1 of them is present.
Answer: (A)
Answer: (B)
P(no collision in keys) .
We need P(collision) P(no collision) , that is P(no collision) .
: , so P(collision) , which is not enough.
: , so P(collision) .
So .
Answer: (B)
Answer: (B)
, so 1 goes to slot 0.
, so 3 goes to slot 6.
. Slot 0 is full, so 8 goes to slot 1.
. Slot 6 is full, so wrap around: slot 0 is full, slot 1 is full, slot 2 is free. 10 goes to slot 2.
Table: 1, 8, 10, -, -, -, 3. In (D), 10 and 8 are swapped, but 8 is inserted before 10, so 8 takes slot 1.
Answer: (B)