Heap Tree · Data Structures
32 questions · asked in 20 of 27 years (2000–2026)
MCQ 27 · MSQ 1 · NAT 41-mark 19 · 2-mark 13
Questions 26–30 of 32
Answer: (A)
There is no order among the leaves. Any one of them can be the minimum, and a leaf we skip could hold a value smaller than all the others without breaking the heap property. So all leaves must be checked, which needs time.
Scanning the leaves (or the whole array) takes , so the time is .
Answer: (A)
10, 8, 5, 3, 2
Two new elements '1' and '7' are inserted in the heap in that order. The level-order traversal of the heap after the insertion of the elements is:
Answer: (D)
Initial heap:
Insert 1 at index 6, as the left child of 5 (index 3). 1 < 5, so it stays. Array: 10, 8, 5, 3, 2, 1.
Heap after inserting 1:
Insert 7 at index 7, as the right child of 5. 7 > 5, so swap with 5. Then the parent is 10 > 7, so stop.
Heap after inserting 7:
Level order: 10, 8, 7, 3, 2, 1, 5.
Answer: (D)
Answer: (B)
Sifting down a node of height (its longest path down to a leaf) takes at most swaps. A heap of nodes has at most nodes of height . So the total work is
, since .
The simple estimate (option D) assumes that each of the about internal nodes may move down levels. It overcounts, because most nodes are near the bottom and can only move a few levels. Option A is too small, since all nodes must be looked at.
Answer: (B)
Answer: (A)
32: root.
15: left child of 32. No swap.
20: right child of 32. No swap.
30: left child of 15. 30 > 15, so swap. Then 30 < 32, stop. Tree: 32; 30, 20; 15.
12: right child of 30. No swap.
25: left child of 20. 25 > 20, so swap. Then 25 < 32, stop. Tree: 32; 30, 25; 15, 12, 20.
16: right child of 25. 16 < 25, no swap.
The final heap is shown below: 32 at the root, 30 and 25 below it, then 15, 12 under 30 and 20, 16 under 25. This is figure (a). In (c) the leaves 20 and 16 under 25 are in the other order, which the insertion of 16 does not produce, and (b) and (d) have 25 on the left, which does not happen here.
Answer: (A)
1. Delection of the smallest element.
2. Insertion of an element if it is not already present in the set.
Which of the following data structures can be used for this purpose ?
Answer: (B)
A balanced search tree has height .
Removing the smallest element takes time.
Checking whether an element is present, and then inserting it:
A (min) heap is an almost complete binary tree, and its height is .
Removing the smallest element takes time (take out the root, put the last element in its place, then balance).
Checking whether an element is present, and then inserting it: the check alone takes . The insertion and balancing take . So the total is
The answer is B.
(Even if it is a max heap, the answer stays the same. Only the time to delete the minimum becomes larger: )
Keep practising