Q: Why not use binary search trees for priority queues?
A:
- Adds and removals from binary search trees can be done
in O(log(n)) time only if the tree is balanced.
- Binary search trees are not inherently balanced
(Example)
— Even if they
start out balanced they can lose balance after a number of adds and
removals.
- In the worst case, adds and removals for binary search trees
take O(n) (linear) time.
Binary heaps, when properly implemented, are
self-balancing.