Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 C
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 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. 38 29 92 7 51 65 27 5 75 26 50
- B. 92 38 65 75 51 29 27 7 5 26 50
- C. 92 75 65 38 51 29 27 7 5 26 50
- D. 92 75 65 29 51 38 27 5 7 26 50
Correct answer: C. 92 75 65 38 51 29 27 7 5 26 50
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: 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…
- A 0-indexed array holds these values: 74 26 75 15 89 92 45 90 58. A max-heap is built in place with Floyd's method: for i from n/2 − 1…
- A 0-indexed array holds these values: 22 97 55 19 74 84 8 90 56 35 38 42 93 43 51. A max-heap is built in place with Floyd's method: for i…
- A 0-indexed array holds these values: 82 28 21 79 83 26 9 80 37 51 85 50 54 39 27. A max-heap is built in place with Floyd's method: for i…
- A 0-indexed array holds these values: 56 58 94 18 5 33 71 35 90 26 61 85 97 62. A max-heap is built in place with Floyd's method: for i…
- A 0-indexed array holds these values: 42 65 28 48 66 35 95 5 92 32 24 46 52 58. A max-heap is built in place with Floyd's method: for i…