GATE Computer ScienceVery hardGATE CS (PYQ pattern)
The 4 largest elements of the stream 14, 7, 22, 3, 18, 9, 30, 11, 25, 5, 17, 28, 2, 21 are found with a min-heap of size 4 holding the first 4 elements; for each later element x, if x is greater than the heap's minimum it replaces the root and is sifted down. How many replacements are made, and what is the heap's minimum at the end?
- A. 4 replacements, minimum 22
- B. 5 replacements, minimum 25
- C. 5 replacements, minimum 22
- D. 7 replacements, minimum 18
Correct answer: C. 5 replacements, minimum 22
The final heap holds [22, 25, 28, 30]. Each later element larger than the current minimum causes a replacement: 5 of the 10 elements.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- A sorted array was rotated: [15, 18, 22, 25, 30, 2, 4, 7, 9, 11, 12, 14]. The standard rotated binary search (compare a[lo] <= a[mid] to…
- Two singly linked lists merge into a common tail: list X has 7 nodes before the merge point, list Y has 11 nodes before it, and the shared…
- A singly linked list 1 -> 2 -> ... -> 12 is modified by reversing the sublist from position 3 to position 9 (1-indexed, inclusive), and…
- Eight sorted lists of 100 keys each (800 distinct keys) are merged with the standard two-way merge, whose worst case for lists of sizes p…
- The number of nodes of a complete binary tree is found recursively: compute the leftmost-path height and the rightmost-path height of the…
- A BST is built from the sorted array 1, 2, ..., 14 by recursion: the root is a[mid] with mid = (lo + hi) / 2 (integer division), then the…