Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div2 C
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 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. 82 80 50 79 83 26 39 28 37 51 85 21 54 9 27
- B. 82 83 26 80 85 54 39 79 37 51 28 50 21 9 27
- C. 85 83 54 80 82 50 39 79 37 51 28 21 26 9 27
- D. 85 83 54 80 82 50 39 28 37 51 79 21 26 9 27
Correct answer: C. 85 83 54 80 82 50 39 79 37 51 28 21 26 9 27
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: 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…
- A 0-indexed array holds these values: 94 34 64 65 45 41 73 47 4 24 15 99 6. A max-heap is built in place with Floyd's method: for i from…
- A 0-indexed array holds these values: 19 76 92 63 7 44 54 81 90 11 74 93 20 82 31. A max-heap is built in place with Floyd's method: for i…
- A 0-indexed array holds these values: 33 28 86 90 92 95 23 32 9 8 26 73. A max-heap is built in place with Floyd's method: for i from n/2…
- A rooted tree has these parent→child edges: 39→45, 99→70, 25→48, 13→64, 99→25, 25→13, 73→94, 25→73, 25→39. A node counts as its own…