Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 C
A 0-indexed array holds these values: 85 31 68 47 17 78 22 3 33 84 5. A max-heap is built in place with Floyd's method: for i from n/2 − 1 down to 0, sift the element at index i down (swap with the larger child while it is smaller than that child). What is the array after building?
- A. 85 47 78 31 84 68 22 3 33 17 5
- B. 85 84 78 47 31 68 22 3 33 17 5
- C. 85 47 78 33 84 68 22 3 31 17 5
- D. 85 84 78 33 47 68 22 3 31 17 5
Correct answer: B. 85 84 78 47 31 68 22 3 33 17 5
Floyd's method sifts down from the last internal node to the root, so each subtree is already a heap when its root is processed. Always choosing the left child, going top-down, or inserting one by one give other 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
- A 0-indexed array holds these values: 75 45 11 17 65 96 61 74 70. A max-heap is built in place with Floyd's method: for i from n/2 − 1…
- A 0-indexed array holds these values: 10 74 2 30 69 14 16 86 49. A max-heap is built in place with Floyd's method: for i from n/2 − 1 down…
- A 0-indexed array holds these values: 8 65 35 58 99 30 60 37 10 76. A max-heap is built in place with Floyd's method: for i from n/2 − 1…
- A 0-indexed array holds these values: 68 36 80 31 99 87 18 63 53 27. A max-heap is built in place with Floyd's method: for i from n/2 − 1…
- A 0-indexed array holds these values: 29 38 92 5 26 65 27 7 75 51 50. A max-heap is built in place with Floyd's method: for i from n/2 − 1…
- A 0-indexed array holds these values: 74 13 75 42 26 66 23 85 88. A max-heap is built in place with Floyd's method: for i from n/2 − 1…