In my data-structure course, I need to implement a binary heap with the following time - complexity requirements:
- Find Max - O(1)
- Insert - O(lg n)
- Delete Max - O(lg n)
Now I thought to implement this using an array in the following way: The root of the heap is in Arr[1] (the first index). The children of Arr[i] are in Arr[2i] and Arr[2i+1] (2 children). With this implementation I will get Find Max in O(1), Delete Max in O(n) and insert in O(lg n) with an exception - if I need to insert when the array is full I will have to resize the array and will "cost" me O(n) so the total cost of insert with all edge cases will be O(n) instead of O(log n) as required.
Is there other way of implementation that answers all the complexisty requirements? I thought maybe to try to implement with a LinkedList instead of an array but insert will still be O(n). Any suggestions for an implementation will be very welcome.