Data Structures & AlgorithmsHardCodeforces Div 2 · ICPC regional
Array [7, 21, 6, 3, 10, 17, 8] 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. [3, 7, 6, 21, 10, 17, 8]
- B. [6, 21, 7, 3, 10, 17, 8]
- C. [3, 6, 7, 8, 10, 17, 21]
- D. [3, 6, 7, 21, 10, 17, 8]
Correct answer: A. [3, 7, 6, 21, 10, 17, 8]
Bottom-up heapify on [7, 21, 6, 3, 10, 17, 8] produces [3, 7, 6, 21, 10, 17, 8]. 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 [7, 6, 2] are available in unlimited quantity. What is the minimum number of coins needed to pay exactly 18? (Coins…
- 4 × 4 grid, rows top to bottom ('#' = blocked, '.' = open): .... / ..#. / ..#. / ..... Count the paths from top-left to bottom-right that…
- Words ['bcb', 'c', 'ac', 'abbb', 'c', 'bac', 'bbb'] are inserted in this order into an empty trie with one node per character, shared…
- Array A = [3, 11, 10, 2, 3, 8, 6]. Over all non-empty contiguous subarrays, what is the maximum value of the XOR of the elements in the…
- Connected undirected weighted graph on vertices A, B, C, D, E, F with edges A–B (9), A–C (8), A–D (9), A–E (19), B–D (3), B–E (8), B–F…
- Consider the recursive function def f(n): if n < 2: return n; return f(n-1) + f(n-2). Evaluate f(9) and count every invocation of f…