Data Structures & AlgorithmsModerateProduct-company placement
Heap sort (ascending) is run on [44, 9, 47, 27, 1, 46, 30, 10]: 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. [46, 27, 44, 10, 1, 9, 30, 47]
- B. [30, 27, 9, 10, 1, 44, 46, 47]
- C. [44, 27, 30, 10, 1, 9, 46, 47]
- D. [47, 27, 46, 10, 1, 44, 30, 9]
Correct answer: C. [44, 27, 30, 10, 1, 9, 46, 47]
Build-heap gives [47, 27, 46, 10, 1, 44, 30, 9]; each extraction parks the current maximum at the end of the array and re-heapifies the prefix, giving [44, 27, 30, 10, 1, 9, 46, 47] 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
- A binary search tree holds exactly the keys 17, 22, 27, 39, 40, 92, 97, 98. Which ONE of the following can be its POSTORDER traversal?
- A BST holds integer keys between 1 and 100. Which sequence CANNOT be the sequence of keys examined while searching for 58?
- What is the length of the longest common subsequence of MATRIX and MARTIAN, and how many DISTINCT longest common subsequences (as strings)…
- Lectures occupy half-open intervals [start, end): [3, 10), [6, 10), [7, 12), [9, 11), [10, 15), [10, 17), [10, 18), [20, 25). A lecture…
- A binary max-heap is stored in a 0-indexed array [57, 47, 54, 14, 15, 6, 21]. Perform, in order: delete-max, insert 10, delete-max, insert…
- Keys 13, 30, 35, 39, 54 are searched with frequencies 8, 1, 9, 9, 12 respectively (only successful searches). The cost of a BST is Σ…