Data Structures & AlgorithmsHardGATE CS · ICPC regional
Array [10, 28, 18, 27, 13, 14] 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. [10, 13, 14, 28, 27, 18]
- B. [10, 13, 14, 27, 28, 18]
- C. [10, 13, 14, 18, 27, 28]
- D. [10, 28, 18, 27, 13, 14]
Correct answer: B. [10, 13, 14, 27, 28, 18]
Bottom-up heapify on [10, 28, 18, 27, 13, 14] produces [10, 13, 14, 27, 28, 18]. 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
- Array A = [3, 31, 23, 2, 8, 19, 7] (all values below 32). What is the maximum of A[i] XOR A[j] over all index pairs with 0 ≤ i < j < 7?
- Distinct keys [5, 4, 7, 27, 25] are inserted, in the order given by the sequence [25, 5, 4, 27, 7], into an empty binary search tree. How…
- Consider the recursive function def f(n): if n < 2: return n; return f(n-1) + f(n-2). Evaluate f(7) and count every invocation of f…
- Consider the recursive function def f(n): if n < 2: return n; return f(n-1) + f(n-2). Evaluate f(10) and count every invocation of f…
- Array [25, 3, 24, 17, 29, 1] 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…
- Array A = [8, 27, 25, 23, 28, 20, 13] (all values below 32). What is the maximum of A[i] XOR A[j] over all index pairs with 0 ≤ i < j < 7?