Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 B
Distinct integers are inserted in this order into an empty binary min-heap stored in a 0-indexed array (the children of index i are at 2i+1 and 2i+2, and a new element is sifted up while it is smaller than its parent): 87 15 35 80 89 68 57 73 98 3 52. What is the array after all insertions?
- A. 3 15 35 80 52 68 57 87 98 89 73
- B. 87 15 35 80 89 68 57 73 98 3 52
- C. 98 89 68 87 80 35 57 15 73 3 52
- D. 3 15 35 57 68 52 80 73 98 89 87
Correct answer: A. 3 15 35 80 52 68 57 87 98 89 73
Every insertion appends to the end and swaps upward past larger parents; the parent of index i is (i-1)//2. Skipping the sift-up, building a max-heap, or using i//2 as the parent gives the trap arrays.
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
- Distinct integers are inserted in this order into an empty binary min-heap stored in a 0-indexed array (the children of index i are at…
- Distinct integers are inserted in this order into an empty binary min-heap stored in a 0-indexed array (the children of index i are at…
- Distinct integers are inserted in this order into an empty binary min-heap stored in a 0-indexed array (the children of index i are at…
- Distinct integers are inserted in this order into an empty binary min-heap stored in a 0-indexed array (the children of index i are at…
- Distinct integers are inserted in this order into an empty binary min-heap stored in a 0-indexed array (the children of index i are at…
- Distinct integers are inserted in this order into an empty binary min-heap stored in a 0-indexed array (the children of index i are at…