Balanced BST and max heap both perform insert and delete in O(logn)
. However, finding max value in a max heap is O(1)
but this is O(logn)
in balanced BST.
If we remove the max value in a max heap it takes O(logn)
because it is a delete operation.
In balanced BST, deleting the max element = finding max value + delete; it equals logn + logn reduces to O(logn)
. So even deleting the max value in balanced BST is O(logn)
.
I have read one such application of max heap is a priority queue and its primary purpose is to remove the max value for every dequeue operation. If deleting max element is O(logn)
for both max heap and balanced BST, I have the following questions
What is the purpose of a max heap in the priority queue just because it is easy to implement rather than using full searchable balanced BST?
Since there is no balancing factor calculation, the max heap can be called an unbalanced binary tree?
Every balanced BST can be used as a priority queue and which is also searchable in
O(logn)
however max heap search isO(n)
correct?
All the time complexities are calculated for worst-case. Any help is greatly appreciated.