Data Structures & AlgorithmsHardAmazon OA · Heaps
Keys 9, 4, 7, 1, 8, 2, 6 are inserted one at a time into an empty min-heap (array representation). Two delete-min operations are then done, each moving the last element to the root and sifting it down. What does the array hold afterwards?
- A. 4 7 6 9 8
- B. 4 6 7 8 9
- C. 4 7 6 8 9
- D. 4 8 6 9 7
Correct answer: A. 4 7 6 9 8
The heap after inserts is [1,4,2,9,8,7,6]. Deleting 1 gives [2,4,6,9,8,7]; deleting 2 moves 7 to the root and sifts it below 4, giving [4,7,6,9,8].
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
- Edges of an undirected weighted graph: A-B 7, A-D 5, B-C 8, B-D 9, B-E 7, C-E 5, D-E 15, D-F 6, E-F 8, E-G 9, F-G 11. What is the weight…
- An undirected graph on vertices 0 to 9 has the edges (0,1), (1,2), (2,0), (3,4), (5,6), (6,7), (7,5) and a self-loop (8,8). How many…
- In a binary tree every node has 0 or 2 children, except 7 nodes that have exactly one child, and there are 12 nodes with two children. How…
- A depth-first search runs on a directed graph with edges A->B, A->C, B->D, C->E, D->E, D->B, E->F, F->C, G->A, G->F, starting from A and…
- Keys 50, 30, 70, 20, 40, 60, 80, 35, 45, 65, 85 are inserted into an empty BST in this order. What is the lowest common ancestor of the…
- The words car, card, care, cat, dog, dot, do are inserted into an initially empty trie. How many nodes does the trie contain, not counting…