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
2000Questions per year2026
Questions 31–32 of 32
In a heap with n elements with the smallest element at the root, the smallest element can be found in time
Answer: (D)
In a min-heap every ancestor of a node is smaller than the node. So the -th smallest element has at most smaller elements, which means it has at most ancestors. Its depth is at most (root at depth 0).
So the 7th smallest lies in the top 7 levels, which hold at most elements. Examine these (for example by a level-order traversal) and pick the 7th smallest. This is a fixed amount of work, whatever the value of , so the time is .
(If only the usual heap operations were allowed, 7 Extract-min operations would cost .)
Answer: (D)
So the 7th smallest lies in the top 7 levels, which hold at most elements. Examine these (for example by a level-order traversal) and pick the 7th smallest. This is a fixed amount of work, whatever the value of , so the time is .
(If only the usual heap operations were allowed, 7 Extract-min operations would cost .)
Answer: (D)
Consider any array representation of an n element binary heap where the elements are stored from index 1 to index n of the array. For the element stored at index i of the array ( ) , the index of the parent is
Answer: (B)
With indices from 1, the node at index has its left child at and its right child at .
Go back from a child to its parent: and . Both children give the parent , so the parent of the node at index is at .
The other options fail: is not a whole number for odd (for it is 1.5), and is wrong, since the parent of index 4 is 2, not 3. also gives fractions (for it is 1.5).
Answer: (B)
Go back from a child to its parent: and . Both children give the parent , so the parent of the node at index is at .
The other options fail: is not a whole number for odd (for it is 1.5), and is wrong, since the parent of index 4 is 2, not 3. also gives fractions (for it is 1.5).
Answer: (B)
Keep practising