GATE Computer ScienceModerateGATE CSE · UGC NET
A max-heap is built from [3, 9, 2, 1, 4, 5, 8, 7] by the bottom-up method (Max-Heapify from the last internal node down to the root, 0-based positions). How many element exchanges occur in total?
- A. 5
- B. 4
- C. 3
- D. 6
Correct answer: B. 4
Sifting down positions 3, 2, 1, 0 in turn performs 4 exchanges; the final array is [9, 7, 8, 3, 4, 5, 2, 1].
More Algorithms questions
- A file uses six symbols with frequencies 5, 9, 12, 13, 16 and 45. What is the total number of bits needed to encode the file with an…
- In a 0/1 knapsack of capacity 11, the items have (weight, value) = (3,3), (4,4), (5,4), (9,10), (4,4). What is the maximum total value?
- What is the length of a longest common subsequence of PROGRAMMING and ALGORITHM?
- A weighted undirected graph on vertices 0–5 has edges (0,1,4), (0,2,3), (1,2,1), (1,3,2), (2,3,4), (3,4,2), (4,5,6), (3,5,7), (2,5,8)…
- A DAG on vertices 0–5 has edges 0→2, 1→2, 2→3, 2→4, 3→5 and 4→5. How many distinct topological orderings does it have?
- With unit cost for insertion, deletion and substitution, what is the edit distance between INTENTION and EXECUTION?