Given a binary-max heap. The elements are stored in an array as 25, 14, 16, 13, 10, 8,12. What is the content of the array after two delete operation.
(a) 14, 13, 8, 12, 10
(b) 14, 12, 13, 10, 8
(c) 14, 13, 12, 8, 10
(d) 14,13, 12, 10, 8
Correct answer: (d) 14,13, 12, 10, 8
max hip has the root value greater that it's child nodes.
Delete operation in max heap will delete the root node value. After deletion of root, node with larger value out of its two child nodes will become root as shown below.
max heap stored in array as you traverse the heap in breadth first search way.
Initially, array has values [25,14,16,13,10,8,12] -- after deletion array has values [14,13,10,8,12].
means two larger values deleted and largest value after that becomes root.
No comments:
Post a Comment