Data Structures & AlgorithmsVery hardGATE CS · ICPC regional · Product Company SDE
Keys 17, 90, 39, 58, 63, 18, 37, 95 are inserted one at a time into an initially empty max-heap (array representation, sift-up). What is the final array?
- A. [95, 90, 39, 63, 58, 18, 37, 17]
- B. [95, 90, 63, 58, 39, 37, 18, 17]
- C. [95, 90, 39, 58, 63, 18, 37, 17]
- D. [17, 37, 18, 58, 63, 39, 90, 95]
Correct answer: A. [95, 90, 39, 63, 58, 18, 37, 17]
Insert each key at the end and swap with its parent while larger. Result [95, 90, 39, 63, 58, 18, 37, 17]. Building by Floyd's bottom-up method may give a different (also valid) heap.
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
- An undirected graph has edges (u–v: weight) A–B:10, A–C:12, A–D:4, D–E:29, D–F:26, D–B:13. What is the weight of its minimum spanning tree?
- In the undirected graph with edges A–B:8, B–C:6, A–D:3, D–E:1, C–F:2, E–F:1, F–A:4, what is the shortest-path distance from A to D?
- Keys 63, 44, 55, 66, 68, 84, 93, 50, 52, 76 are inserted in this order into an empty BST. What is the height of the tree (edges on the…
- An undirected graph has edges (u–v: weight) A–B:13, A–C:16, A–D:20, C–E:2, B–F:18, D–F:10, D–B:23. What is the weight of its minimum…
- In the undirected graph with edges A–B:10, A–C:12, C–D:3, D–E:8, E–F:2, E–A:9, what is the shortest-path distance from A to D?
- A complete binary tree has 87 nodes. How many leaves does it have?