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 1–5 of 32
Let be an odd number greater than . Consider a binary minheap with elements stored in an array whose index starts from .
Which of the following indices of do/does NOT correspond to any leaf node of the minheap?
Which of the following indices of do/does NOT correspond to any leaf node of the minheap?
One or more options are correct.
Answer: (B), (C)
A binary heap is stored in a 1-indexed array with elements. Its leaf nodes (nodes with no children) are the indices from to .
When is odd, we get . So:
- Leaf indices run from to .
- Internal (non-leaf) indices run from to .
Now check each given index:
- : this is the first leaf index, so it is a leaf.
- : this is the last leaf, so it is a leaf.
- : this is the last internal node index, so it is NOT a leaf.
- : this is less than , so it is also an internal node and NOT a leaf.
Answer: indices (n-1)/2 and (n-3)/2 do NOT correspond to leaf nodes.
When is odd, we get . So:
- Leaf indices run from to .
- Internal (non-leaf) indices run from to .
Now check each given index:
- : this is the first leaf index, so it is a leaf.
- : this is the last leaf, so it is a leaf.
- : this is the last internal node index, so it is NOT a leaf.
- : this is less than , so it is also an internal node and NOT a leaf.
Answer: indices (n-1)/2 and (n-3)/2 do NOT correspond to leaf nodes.
The height of any rooted tree is defined as the maximum number of edges in the path from the root node to any leaf node. Suppose a Min-Heap stores 32 keys. The height of is _____________. (Answer in integer)
Answer: 5
A min-heap that has keys is kept as a nearly complete binary tree. Its height (the most edges from the root to a leaf) is .
Level has node, level has , level has , level has , and level has . Together, nodes fill levels to fully. So the nd key has to go on a new level, level 5.
Answer: 5
Level has node, level has , level has , level has , and level has . Together, nodes fill levels to fully. So the nd key has to go on a new level, level 5.
Answer: 5
A meld operation on two instances of a data structure combines them into one single instance of the same data structure. Consider the following data structures:
P: Unsorted doubly linked list with pointers to the head node and tail node of the list.
Q: Min-heap implemented using an array.
R: Binary Search Tree.
Which ONE of the following options gives the worst-case time complexities for meld operation on instances of size of these data structures?
P: Unsorted doubly linked list with pointers to the head node and tail node of the list.
Q: Min-heap implemented using an array.
R: Binary Search Tree.
Which ONE of the following options gives the worst-case time complexities for meld operation on instances of size of these data structures?
Answer: (A)
P (unsorted doubly linked list with head and tail pointers): Join the tail of the first list to the head of the second list, then update the tail pointer. This takes only a fixed number of pointer updates. Time: .
Q (array-based min-heap): Take two heaps of size . Join their arrays into one array, then run the usual bottom-up build-heap. Build-heap itself runs in linear time. Time: , and not .
R (Binary Search Tree): First, do an inorder traversal of each BST to get a sorted list (linear time). Next, merge the two sorted lists (linear time). Last, build a balanced BST from the merged list (linear time). The whole meld can be done in .
Answer: P: Θ(1), Q: Θ(n), R: Θ(n)
Q (array-based min-heap): Take two heaps of size . Join their arrays into one array, then run the usual bottom-up build-heap. Build-heap itself runs in linear time. Time: , and not .
R (Binary Search Tree): First, do an inorder traversal of each BST to get a sorted list (linear time). Next, merge the two sorted lists (linear time). Last, build a balanced BST from the merged list (linear time). The whole meld can be done in .
Answer: P: Θ(1), Q: Θ(n), R: Θ(n)
An array is heapified. Which one of the following options represents the first three elements in the heapified array?
Answer: (D)
Make a max-heap from the bottom up (heapify from index down to index 1):
[82, 101, 90, 11, 111, 75, 33, 131, 44, 93]
- i=5 (111): its child is 93 no change.
- i=4 (11): its children are 131 and 44 swap with 131.
- i=3 (90): its children are 75 and 33 no change.
- i=2 (101): its children are 131 and 111 swap with 131 (101 is then fine above 11 and 44).
- i=1 (82): swap with 131, then with 111, then with 93.
Final heap: [131, 111, 90, 101, 93, 75, 33, 11, 44, 82]
Answer: 131, 111, 90
[82, 101, 90, 11, 111, 75, 33, 131, 44, 93]
- i=5 (111): its child is 93 no change.
- i=4 (11): its children are 131 and 44 swap with 131.
- i=3 (90): its children are 75 and 33 no change.
- i=2 (101): its children are 131 and 111 swap with 131 (101 is then fine above 11 and 44).
- i=1 (82): swap with 131, then with 111, then with 93.
Final heap: [131, 111, 90, 101, 93, 75, 33, 11, 44, 82]
Answer: 131, 111, 90
Consider a binary min-heap containing 105 distinct elements. Let be the index (in the underlying array) of the maximum element stored in the heap. The number of possible values of is
Answer: (A)
In a min-heap, every parent is smaller than its children. So the maximum element cannot have a child and it must be a leaf. Any leaf can hold it.
In an array heap with elements, the leaves sit at indices up to .
For : the leaves are 53 to 105 positions.
Answer: 53
In an array heap with elements, the leaves sit at indices up to .
For : the leaves are 53 to 105 positions.
Answer: 53
Keep practising