Data Structures & AlgorithmsHardGATE CS · Advanced
Floyd's bottom-up build-heap (sift-down from the last internal node back to the root) is applied to the array [55, 25, 49, 27, 3, 17, 33, 32, 26] to make a min-heap (array indices start at 1). Which array results?
- A. [25, 3, 17, 26, 55, 49, 33, 32, 27]
- B. [25, 3, 49, 27, 55, 17, 33, 32, 26]
- C. [3, 25, 17, 26, 27, 49, 33, 55, 32]
- D. [3, 25, 17, 26, 55, 49, 33, 32, 27]
Correct answer: D. [3, 25, 17, 26, 55, 49, 33, 32, 27]
Run sift-down for the nodes at positions 4, 3, 2, 1 in that order. Repeated insertion gives a different heap, and sifting down the nodes top-down (1, 2, 3, 4) or only the root does not produce a 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
- Keys 50, 20, 60, 10, 30, 40, 70, 45, 42, 48, 5, 3 are inserted one by one, in this order, into an initially empty AVL tree. A double…
- Keys 10, 20, 30, 40, 50, 60, 70, 80, 15, 25, 35, 45 are inserted in this order into an empty B-tree of minimum degree t = 2 (every node…
- The words car, card, care, cart, cat, dog, dot, dove, do, door are stored in a trie (one letter per edge, with a flag marking the end of a…
- A disjoint-set forest on elements 1..10 starts with every element as its own root. Union(a, b) finds both roots (find uses full path…
- A tree on the vertices A–J has the edges A–B, B–C, C–D, A–E, D–F, B–G, F–H, A–I, C–J. What is the sum of the distances over all unordered…
- A directed acyclic graph has the vertices A–G and the arcs D→F, D→C, D→B, G→C, G→A, C→A, C→E, C→B. How many different topological…