Data Structures & AlgorithmsHardICPC regional · GATE CS top band
Array [13, 15, 17, 14, 6, 23, 3] 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, 13, 6, 15, 14, 23, 17]
- B. [3, 6, 13, 14, 15, 23, 17]
- C. [3, 6, 13, 14, 15, 17, 23]
- D. [13, 15, 17, 14, 6, 23, 3]
Correct answer: B. [3, 6, 13, 14, 15, 23, 17]
Bottom-up heapify on [13, 15, 17, 14, 6, 23, 3] produces [3, 6, 13, 14, 15, 23, 17]. 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 [12, 24, 3, 18, 30, 33, 7, 16, 4] are inserted, in this order, into an empty AVL tree using the standard rebalancing (left, right…
- Distinct keys [13, 24, 18, 4, 20] are inserted, in the order given by the sequence [18, 20, 4, 24, 13], into an empty binary search tree…
- Distinct words ['baa', 'c', 'b', 'bac', 'bba', 'cbbc'] are inserted into an empty trie (one node per character, shared prefixes sharing…
- Directed graph on vertices A, B, C, D, E, F with edges E→D, A→D, F→C, E→C, A→E, B→C, A→F, D→A. How many strongly connected components does…
- Strings a = "bbbab" and b = "cccbb". The edit distance allows insert, delete and substitute, each costing 1 (the standard Levenshtein…
- Coins of denominations [6, 5, 2] are available in unlimited quantity. What is the minimum number of coins needed to pay exactly 16? (Coins…