GATE Computer ScienceVery hardGATE CS (PYQ pattern)
The array [14, 5, 21, 9, 30, 7, 18, 2, 26, 11] is made into a max-heap, giving [30, 26, 21, 14, 11, 7, 18, 2, 9, 5]. Heapsort then performs 3 extract-max steps (swap root with the last heap element, shrink the heap, sift down). What does the whole array look like?
- A. [18, 14, 7, 9, 11, 2, 5, 21, 26, 30]
- B. [21, 14, 18, 9, 11, 7, 5, 2, 26, 30]
- C. [14, 11, 7, 9, 5, 2, 18, 21, 26, 30]
- D. [2, 5, 7, 9, 11, 14, 18, 21, 26, 30]
Correct answer: A. [18, 14, 7, 9, 11, 2, 5, 21, 26, 30]
Extraction 1: [26, 14, 21, 9, 11, 7, 18, 2, 5 | 30]; extraction 2: [21, 14, 18, 9, 11, 7, 5, 2 | 26, 30]; extraction 3: [18, 14, 7, 9, 11, 2, 5 | 21, 26, 30]. The first distractor is the state after two steps and the second after four.
More Algorithms questions
- In how many ways can 30 be written as a sum of ODD positive integers, where order does not matter and parts may repeat?
- In how many ways can 20 be written as a sum of exactly 4 positive integers, where order does not matter (parts may repeat)?
- A tree on vertices 0–10 has weighted edges 0-1 (3), 1-2 (4), 1-3 (2), 3-4 (6), 3-5 (1), 5-6 (7), 0-7 (5), 7-8 (2), 2-9 (3), 9-10 (8). Its…
- Vertices 0–10 of the tree with edges 0-1, 1-2, 1-3, 3-4, 3-5, 5-6, 0-7, 7-8, 2-9, 9-10 carry weights w = 4, 7, 3, 9, 5, 2, 8, 6, 5, 4, 10…
- Five cities have symmetric distances d(0,1) = 9, d(0,2) = 14, d(0,3) = 23, d(0,4) = 17, d(1,2) = 11, d(1,3) = 19, d(1,4) = 26, d(2,3) = 8…
- The standard 2-approximation for Vertex Cover scans the edges in the order 0-1, 1-2, 2-3, 3-4, 4-5, 5-6, 1-4, 2-5 and, whenever an edge…