Data Structures & AlgorithmsModerateProduct-company placement
Heap sort (ascending) is run on [20, 37, 49, 16, 22, 10, 31, 33]: build a max-heap bottom-up, then repeatedly swap the root with the last element of the heap part and sift down within the shrunk heap. What is the array after the build phase and exactly 2 extractions?
- A. [33, 22, 31, 16, 20, 10, 37, 49]
- B. [37, 33, 31, 16, 22, 10, 20, 49]
- C. [31, 22, 10, 16, 20, 33, 37, 49]
- D. [49, 37, 31, 33, 22, 10, 20, 16]
Correct answer: A. [33, 22, 31, 16, 20, 10, 37, 49]
Build-heap gives [49, 37, 31, 33, 22, 10, 20, 16]; each extraction parks the current maximum at the end of the array and re-heapifies the prefix, giving [33, 22, 31, 16, 20, 10, 37, 49] after 2 extractions.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- What is the length of the longest BITONIC subsequence (strictly increasing then strictly decreasing; either part may be empty) of [20, 21…
- 0/1 knapsack with capacity 17: items (weight, value) = (9, 21), (6, 19), (3, 9), (7, 13), (3, 27). What is the maximum total value?
- Coins of denominations 1, 6, 9, 10 are available in unlimited supply. What is the minimum number of coins needed to make 33, and how many…
- For the string BBABCBCAB, what are the lengths of the longest palindromic SUBSTRING and the longest palindromic SUBSEQUENCE?
- With 3 identical eggs and at most 5 drops, what is the largest number of floors for which you can always determine the critical floor (the…
- A complete binary tree (array form, all levels full except possibly the last, which is filled from the left) has 187 nodes. How many…