Algorithms for Sorting - Heapsort
Learning Goals
Exam-like questions
- Heapsort
- Each deleteMin operation takes logN running time.
- N times performing deleteMin → NlogN running time
- Store N elements in a binary heap tree.
- Perform deleteMin operation N times, storing each element deleted
from
the heap into another array. - Copy back the array.
Sorts in O(NlogN) time by performing N times deleteMin operations.
Why O(NlogN)?
instead of using another array
How can we do this?
and as a result we get a vacant position in the array - the last cell.
There we store the deleted element.
the elements will be there in reversed order.
What is the remedy for this?
then at the end the elements in the array will be in correct order.
Here is an example of heapsort.
- Be able to explain how heapsort works and its complexity.
- Explain the complexity of heapsort
- Given an array e.g. 17, 23, 10, 1, 7, 16, 9, 20,
sort it on paper using heapsort
Write down explicitly each step.
No comments:
Post a Comment