Data Structures & AlgorithmsModerateProduct-company placement
Heap sort (ascending) is run on [30, 16, 36, 4, 37, 35, 41, 28]: 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. [37, 28, 36, 4, 16, 35, 30, 41]
- B. [35, 28, 30, 4, 16, 36, 37, 41]
- C. [41, 37, 36, 28, 16, 35, 30, 4]
- D. [36, 28, 35, 4, 16, 30, 37, 41]
Correct answer: D. [36, 28, 35, 4, 16, 30, 37, 41]
Build-heap gives [41, 37, 36, 28, 16, 35, 30, 4]; each extraction parks the current maximum at the end of the array and re-heapifies the prefix, giving [36, 28, 35, 4, 16, 30, 37, 41] 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 minimum number of edges m such that EVERY simple undirected graph with 10 vertices and m edges is guaranteed to be connected?
- How many calls of g (including the first) are made when g(6) is evaluated, and what value is returned? c int g(int n) { if (n <= 2) return…
- For the string CHARACTERS, what are the lengths of the longest palindromic SUBSTRING and the longest palindromic SUBSEQUENCE?
- What is the minimum number of edges that must be deleted from the undirected graph with edges A–B, A–C, A–D, A–E, B–D, B–F, C–E, C–F, D–E…
- Dijkstra's algorithm runs from A on the directed graph A→B (14), A→F (2), C→A (12), C→E (7), C→F (2), D→B (7), D→C (5), D→E (3), E→F (6)…
- All suffixes of the string 'abcab' are inserted into a character trie (a suffix trie). How many nodes does it have, including the root?