Data Structures & AlgorithmsModerateGATE CS
Heap sort (ascending) is run on [24, 11, 17, 25, 37, 7, 32, 23]: 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. [32, 25, 23, 24, 11, 7, 17, 37]
- B. [25, 24, 23, 17, 11, 7, 32, 37]
- C. [24, 17, 23, 7, 11, 25, 32, 37]
- D. [37, 25, 32, 24, 11, 7, 17, 23]
Correct answer: B. [25, 24, 23, 17, 11, 7, 32, 37]
Build-heap gives [37, 25, 32, 24, 11, 7, 17, 23]; each extraction parks the current maximum at the end of the array and re-heapifies the prefix, giving [25, 24, 23, 17, 11, 7, 32, 37] 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 DAG on vertices A–G has edges B→A, B→D, B→E, B→F, E→C, F→A, F→C, F→D (G isolated). What order does Kahn's algorithm with a FIFO queue…
- The words stem, stall, stamp, star, step are inserted into an empty trie (one node per character, shared prefixes share nodes, plus a…
- A binary tree with distinct labels has INORDER G H B F C E A D I and LEVEL-ORDER I E G D F A H C B. What is its postorder traversal?
- Floyd–Warshall runs on vertices 1–4 with directed edges 1→2 (10), 1→4 (1), 2→1 (12), 2→3 (10), 3→1 (12), 4→1 (1), 4→3 (4). After the…
- A binary max-heap is stored in a 0-indexed array [57, 27, 49, 9, 19, 17, 40]. Perform, in order: insert 7, delete-max, insert 13, insert…
- Floyd–Warshall runs on vertices 1–4 with directed edges 1→3 (2), 2→1 (7), 2→3 (4), 3→1 (3), 3→4 (8), 4→1 (7), 4→2 (1). After the…