Data Structures & AlgorithmsModerateGATE CS · Codeforces Div2 C
A 0-indexed array holds these values: 41 15 29 48 86 69 43 60. 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. 86 60 69 48 15 29 43 41
- B. 60 48 69 41 86 29 43 15
- C. 41 86 69 60 15 29 43 48
- D. 86 60 69 48 41 29 43 15
Correct answer: A. 86 60 69 48 15 29 43 41
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: 61 42 49 58 8 64 92. A max-heap is built in place with Floyd's method: for i from n/2 − 1 down to 0…
- A 0-indexed array holds these values: 9 75 64 56 88 94 41 93. A max-heap is built in place with Floyd's method: for i from n/2 − 1 down to…
- A 0-indexed array holds these values: 13 86 81 16 75 77 92 84 30. A max-heap is built in place with Floyd's method: for i from n/2 − 1…
- A 0-indexed array holds these values: 42 43 87 63 97 68 6 3 74 71. A max-heap is built in place with Floyd's method: for i from n/2 − 1…
- 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…
- 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…