Data Structures & AlgorithmsHardICPC regional · GATE CS top band
Array [2, 14, 21, 11, 1, 17] 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. [1, 2, 17, 14, 11, 21]
- B. [1, 2, 17, 11, 14, 21]
- C. [1, 2, 11, 14, 17, 21]
- D. [2, 14, 21, 11, 1, 17]
Correct answer: B. [1, 2, 17, 11, 14, 21]
Bottom-up heapify on [2, 14, 21, 11, 1, 17] produces [1, 2, 17, 11, 14, 21]. 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
- A 6 × 6 grid (rows top to bottom, '#' = land, '.' = water): .#.... / ..#.#. / ##...# / #...#. / ##...# / ..##.#. Land cells form an island…
- Undirected weighted graph on vertices A, B, C, D, E, F with edges A–D (3), A–E (8), B–C (6), B–D (6), B–E (8), B–F (7), C–F (3), D–F (7)…
- Undirected graph on vertices A, B, C, D, E, F with edges, in this exact order: A–B (1), A–D (1), A–F (1), B–E (1), A–E (1), A–C (1)…
- Connected undirected graph on vertices A, B, C, D, E, F, G, H with edges A–G (1), A–H (1), B–C (1), C–D (1), C–E (1), C–G (1), F–G (1)…
- Array A = [1, 16, 18, 4, 25, 5, 13, 21]. How many index pairs i < j satisfy (A[i] XOR A[j]) < 23? (A trie with subtree counts answers this…
- 5 × 5 grid, rows top to bottom ('#' = blocked, '.' = open): ..... / ..#.. / ..... / ..#.. / #..... Count the paths from top-left to…