Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div2 C
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 − 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. 90 33 95 32 92 86 23 28 9 8 26 73
- B. 86 92 95 90 28 73 23 32 9 8 26 33
- C. 95 90 92 32 86 73 23 28 9 8 26 33
- D. 95 92 86 90 28 73 23 32 9 8 26 33
Correct answer: D. 95 92 86 90 28 73 23 32 9 8 26 33
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 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…
- A rooted tree has these parent→child edges: 98→34, 27→69, 27→30, 69→98, 82→14, 69→43, 30→67, 30→82. A node counts as its own ancestor…
- A rooted tree has these parent→child edges: 53→34, 22→91, 91→2, 59→99, 91→24, 24→59, 99→53. A node counts as its own ancestor. What is the…
- A rooted tree has these parent→child edges: 47→3, 80→83, 80→90, 80→77, 56→43, 80→30, 3→80, 80→50, 3→34, 30→18, 3→56, 47→68. A node counts…
- A rooted tree has these parent→child edges: 98→57, 49→29, 72→94, 76→98, 72→87, 76→41, 76→49, 94→71, 72→76, 57→11. A node counts as its own…
- A rooted tree has these parent→child edges: 96→13, 13→90, 13→32, 72→46, 58→36, 13→30, 14→96, 72→93, 90→58, 96→50, 20→72, 58→20, 50→61. A…