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 16–20 of 32
Consider the following array of elements.
(89,19,50,17,12,15,2,5,7,11,6,9,100)
The minimum number of interchanges needed to convert it into a max-heap is
(89,19,50,17,12,15,2,5,7,11,6,9,100)
The minimum number of interchanges needed to convert it into a max-heap is
Answer: (D)
Only 100, which is at the last position, breaks the heap property. It moves up the tree like this:
- swap with its parent 15
- swap with its parent 50
- swap with the root 89
All other elements already follow the max-heap rule. So the number of interchanges is 3.
Answer: 3
- swap with its parent 15
- swap with its parent 50
- swap with the root 89
All other elements already follow the max-heap rule. So the number of interchanges is 3.
Answer: 3
A priority queue is implemented as a Max-Heap. Initially, it has 5 elements. The level-order traversal of the heap is: 10, 8, 5, 3, 2. Two new elements 1 and 7 are inserted into the heap in that order. The level-order traversal of the heap after the insertion of the elements is:
Answer: (A)
Start with the heap: 10, 8, 5, 3, 2.
- Insert 1: it is placed as the left child of 5. Compare: 1 5, so no swap. Result 10, 8, 5, 3, 2, 1
- Insert 7: it is placed as the right child of 5. Compare: 7 5, so swap. Then 7 10, so stop. Result 10, 8, 7, 3, 2, 1, 5
Answer: (A) 10, 8, 7, 3, 2, 1, 5
- Insert 1: it is placed as the left child of 5. Compare: 1 5, so no swap. Result 10, 8, 5, 3, 2, 1
- Insert 7: it is placed as the right child of 5. Compare: 7 5, so swap. Then 7 10, so stop. Result 10, 8, 7, 3, 2, 1, 5
Answer: (A) 10, 8, 7, 3, 2, 1, 5
A max-heap is a heap where the value of each parent is greater than or equal to the value of its children. Which of the following is a max-heap?
Answer: (B)
A heap must be a complete binary tree. Each parent must be its children.
- A: Not complete. Node 8 has only one child, but 5 has a child.
- B: Complete. 10 8, 6. 8 4, 5. 6 1, 2. So it is valid.
- C: Node 5 has child 8 not valid.
- D: Root 5 has child 8 not valid.
Answer: B
- A: Not complete. Node 8 has only one child, but 5 has a child.
- B: Complete. 10 8, 6. 8 4, 5. 6 1, 2. So it is valid.
- C: Node 5 has child 8 not valid.
- D: Root 5 has child 8 not valid.
Answer: B
Consider a binary max-heap implemented using an array.
What is the content of the array after two delete operations on {25,14,16,13,10,8,12}
What is the content of the array after two delete operations on {25,14,16,13,10,8,12}
Answer: (D)
In a delete, the root is taken out. The last element is put in its place. Then the root is pushed down until the heap property is correct. For the first delete:
(the element that breaks the max-heap property is swapped with the larger of its children) (now the heap property holds)
Second delete:
(now the heap property holds)
Correct Answer:
(the element that breaks the max-heap property is swapped with the larger of its children) (now the heap property holds)
Second delete:
(now the heap property holds)
Correct Answer:
Consider a binary max-heap implemented using an array.
Which one of the following array represents a binary max-heap?
Which one of the following array represents a binary max-heap?
Answer: (C)
Store the array from index 1. The children of the node at index are at and . For 7 elements, node 1 has children 2 and 3, node 2 has children 4 and 5, and node 3 has children 6 and 7. In a max-heap every parent is at least as large as its children.
(A) 12 at index 2 has children 13 and 10. 12 < 13, so it is not a max-heap.
(B) 14 at index 2 has children 16 and 10. 14 < 16, so it is not a max-heap.
(C) 25 ≥ 14, 16; 14 ≥ 13, 10; 16 ≥ 8, 12. Every parent is at least its children, so it is a max-heap:
(D) 12 at index 3 has children 8 and 16. 12 < 16, so it is not a max-heap.
Answer: (C)
(A) 12 at index 2 has children 13 and 10. 12 < 13, so it is not a max-heap.
(B) 14 at index 2 has children 16 and 10. 14 < 16, so it is not a max-heap.
(C) 25 ≥ 14, 16; 14 ≥ 13, 10; 16 ≥ 8, 12. Every parent is at least its children, so it is a max-heap:
(D) 12 at index 3 has children 8 and 16. 12 < 16, so it is not a max-heap.
Answer: (C)
Keep practising