Data Structures & AlgorithmsHardGATE CS · Product-company placement
A 4-ary max-heap is stored in a 0-indexed array (children of i at 4i + 1 … 4i + 4): [58, 57, 54, 33, 11, 34, 22, 42, 30, 19]. After inserting 62 (append, then sift up), what is the array?
- A. [62, 58, 54, 33, 57, 34, 22, 42, 30, 19, 11]
- B. [58, 57, 54, 33, 11, 34, 22, 42, 30, 19, 62]
- C. [62, 58, 54, 33, 11, 34, 22, 42, 30, 19, 57]
- D. [62, 57, 58, 33, 11, 34, 22, 42, 30, 19, 54]
Correct answer: D. [62, 57, 58, 33, 11, 34, 22, 42, 30, 19, 54]
In a 4-ary heap the parent of i is ⌊(i − 1)/4⌋; 62 starts at index 10 and swaps up while it beats its parent. Using the binary parent formula ⌊(i − 1)/2⌋ is the trap.
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 33, 11, 72, 19, 76, 71, 31, 74, 40, 37, 45 are inserted in that order into an empty BST. Then 33 is deleted and after that 37 is…
- Keys 90, 94, 89, 30, 62, 17, 99, 53 inserted in this order build a BST. How many of the 8! orderings of these same 8 keys, inserted into…
- A binary search tree holds exactly the keys 13, 19, 20, 36, 71, 73, 94, 99. Which ONE of the following sequences can be its PREORDER…
- A BST holds integer keys between 1 and 100. Which sequence CANNOT be the sequence of keys examined while searching for 44?
- A rooted tree has these parent→child edges: 56→8, 64→56, 64→24, 64→45, 24→59, 45→41, 8→2. A depth-first search starts at the root and, at…
- A rooted tree has these parent→child edges: 74→13, 74→24, 84→62, 13→75, 13→66, 24→84. A depth-first search starts at the root and, at…