Data Structures & AlgorithmsHardICPC regional · GATE CS top band
Array [12, 23, 8, 18, 15, 14, 26, 13] is turned into a min-heap in place with bottom-up heapify: for i from ⌊n/2⌋−1 down to 0, sift the element at index i down (swap with its smaller child while a child is smaller). What is the resulting array?
- A. [8, 23, 12, 18, 15, 14, 26, 13]
- B. [8, 12, 13, 14, 15, 18, 23, 26]
- C. [8, 13, 12, 18, 15, 14, 26, 23]
- D. [8, 13, 12, 15, 18, 14, 26, 23]
Correct answer: C. [8, 13, 12, 18, 15, 14, 26, 23]
Bottom-up heapify on [12, 23, 8, 18, 15, 14, 26, 13] produces [8, 13, 12, 18, 15, 14, 26, 23]. Inserting one element at a time gives a different heap, and a single sift-down from the root does not fix the internal nodes.
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
- Coins of denominations [11, 9, 8, 3] are available in unlimited quantity. What is the minimum number of coins needed to pay exactly 28?…
- Distinct words ['caab', 'ac', 'aa', 'c', 'baab', 'bbb', 'bbca'] are inserted into an empty trie (one node per character, shared prefixes…
- On an 6 × 6 chessboard with rows and columns numbered 0 to 5, a knight starts at (2, 5) and must reach (0, 0) (as (row, column)). A knight…
- Complete undirected graph on vertices A to F with symmetric edge weights given row by row (row i, column j = weight of edge between…
- Bipartite graph with left side {A, B, C, D}, right side {E, F, G, H} and edges A–E, B–E, B–H, C–E, C–F, C–G, C–H, D–E. What is the size of…
- Distinct words ['bbba', 'aaa', 'bcaa', 'aac', 'b'] are inserted into an empty trie (one node per character, shared prefixes sharing nodes…