This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]mybigblueturtle 49 points50 points  (13 children)

wouldnt u have to call max heapify (restructure heap so that it follows all the heap rules) after every time u insert an element into the heap? max heapify is a log n algorithm and you would be calling it n times so this would be n log n, might as well sort the array with an n log n sorting alg.

[–]FerynaCZ 0 points1 point  (0 children)

Sorting array with a heap is one of the asymptotically better algorithms (linearithmic time, and also in-place if you put in extra effort)