Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2
Array [28, 17, 3, 22, 8, 23, 10] 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, 8, 10, 28, 22, 23, 17]
- B. [3, 17, 10, 22, 8, 23, 28]
- C. [3, 8, 10, 17, 22, 23, 28]
- D. [3, 8, 10, 22, 17, 23, 28]
Correct answer: D. [3, 8, 10, 22, 17, 23, 28]
Bottom-up heapify on [28, 17, 3, 22, 8, 23, 10] produces [3, 8, 10, 22, 17, 23, 28]. 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
- Bipartite graph with left side {A, B, C}, right side {D, E, F, G} and edges A–D, A–E, B–F, B–G, C–D. What is the size of a maximum…
- Directed acyclic graph on vertices A, B, C, D, E, F, G (every edge goes from a smaller to a larger letter) with weighted edges A→B (4)…
- Points A(8,5), B(3,9), C(3,5), D(2,7), E(3,2) in the plane. The cost of joining two points is the Manhattan distance |x1−x2| + |y1−y2|…
- Directed weighted graph on vertices A, B, C, D, E with edges D→C (0); B→D (2); A→D (-1); E→A (-1); B→C (0); B→A (-2); C→E (4); D→E (-1)…
- Array A = [7, 4, 7, 14, 7, 6, 2]. Over all non-empty contiguous subarrays, what is the maximum value of the XOR of the elements in the…
- Rooted tree with root 0 and vertices 0 to 9; the edges are 0–1, 1–2, 1–3, 2–4, 2–5, 4–6, 5–7, 7–8, 0–9 (parent–child). Every edge has…