GATE Computer ScienceVery hardGATE CS (PYQ pattern)
A min-heap is built from [27, 5, 19, 3, 41, 8, 16, 2, 33, 11, 24, 7] by bottom-up heapify, and then extract-min (last element to the root, then sift down with swaps against the smaller child) is performed 5 times. What are the total number of swaps made by the five extractions and the 5th extracted value?
- A. 12 swaps, 8
- B. 10 swaps, 7
- C. 8 swaps, 9
- D. 10 swaps, 8
Correct answer: D. 10 swaps, 8
The extracted values are [2, 3, 5, 7, 8] (the five smallest in order). Summing the sift-down swaps over the five extractions gives 10.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- int m[4][4] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}}; for (int i = 0; i < 4; i++) for (int j = 0; j < i; j++) {…
- A routine reverses the entire string in place and then reverses each maximal run of non-space characters in place. It is applied twice in…
- A singly linked list 1 -> 2 -> ... -> 20 undergoes two passes: first every 3rd node (by current position) is deleted, then in the…
- int x = 1; int inc(void) { return x += 1; } int dbl(void) { return x = 2; } int sq(void) { return x = x; } int (fp[3])(void) = {inc, dbl…
- A table of size 13 uses double hashing, probe i of key k is (k mod 13 + i (1 + k mod 11)) mod 13. Keys 18, 41, 22, 44, 59, 32, 31, 73 are…
- A BST on 31 keys is perfectly balanced (all 5 levels full). Searching for each of the 31 keys with equal probability, what is the average…