Reputation: 35
Why Priority queue preferred to implement using heap not by the array, although Heap itself implemented using an array.
Upvotes: 0
Views: 105
Reputation: 133975
The binary heap provides a partial ordering, which guarantees O(log n) insertion and O(log n) removal of the highest-priority item.
With a flat array, you have two choices:
Either of those two options makes the priority queue less efficient than if you implement a binary heap.
Upvotes: 2