Data Structures & AlgorithmsHardGATE CS · ICPC regional
Array [27, 5, 12, 25, 10, 1, 22, 2] 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. [5, 10, 12, 25, 27, 1, 22, 2]
- B. [1, 2, 12, 5, 10, 27, 22, 25]
- C. [1, 2, 5, 10, 12, 22, 25, 27]
- D. [1, 2, 5, 10, 25, 12, 22, 27]
Correct answer: B. [1, 2, 12, 5, 10, 27, 22, 25]
Bottom-up heapify on [27, 5, 12, 25, 10, 1, 22, 2] produces [1, 2, 12, 5, 10, 27, 22, 25]. 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
- Keys [39, 30, 10, 5, 31, 38, 32, 20, 1] are inserted, in this order, into an empty AVL tree using the standard rebalancing (left, right…
- Distinct words ['a', 'b', 'ba', 'bb', 'aaa', 'ac'] are inserted into an empty trie (one node per character, shared prefixes share nodes…
- Undirected graph on vertices A, B, C, D, E, F, G with edges A–E (1), A–G (1), B–C (1), B–E (1), B–F (1), C–F (1), C–G (1), D–E (1), D–G…
- Consider the recursive function def f(n): if n < 3: return 1; return f(n-1) + f(n-3). Evaluate f(11) and count every invocation of f…
- 4 × 5 grid, rows top to bottom ('#' = blocked, '.' = open): ..#.. / ..#.. / ..... / ...#.. Count the paths from top-left to bottom-right…
- Complete undirected graph on vertices A to F with symmetric edge weights given row by row (row i, column j = weight of edge between…