Help with algorithm question regarding heap and inserting eI

Help with algorithm question regarding heap and inserting eIements.

If a new heap data structure was created that allowed inserting elements into a heap in theta(1) while also allowing the maximum element to be popped in theta(1), what would the runtime of heap sort be with this new data structure? Theta(nlg(n)) Theta(n) Theta(lg(n)) Theta(n^2)

Solution

Suppose there are n elements .

Background
Heap Sort as we know , When the Max Heap is created. We pluck one elements at a time. and place the last element into it correct position. We do this for n elements and in doing so ezch step takes log n time .
So heap Sort in generat takes O(nlog n) time.


Coming to the question

1. When the Insertion takes O(1) time. Which means our process of log n is minimized to O(1).
2. So for plucking n elements . Heap Sort will take O(n) time.

So Option (b)

Help with algorithm question regarding heap and inserting eIements. If a new heap data structure was created that allowed inserting elements into a heap in thet

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site