Chapter 6 - Sorting Machine using Heapsort

Document last modified: 

Algorithm Used Insert Extract Change_To_Extraction_Phase
Insertion Sort O(N2) N items inserted
O(N) per item
O(1) O(1)
Selection Sort O(1) O(N2) N items extracted
O(N) per item
O(1)
Exchange Sort O(1) O(1) O(N2)
Quick Sort O(1) O(1) O(N2) worst,
O(N * Log2 N) best
Merge Sort O(1) O(1) O(N * Log2 N)
Heap Sort O(1) O(N * Log2 N) for N items extracted
O( Log2 N) for 1 item extracted
O(N)

 

Heap Sort:

Insert takes item to be sorted and adds it to the rightmost free location in the array, this increases the heap's size by 1
Change_To_Extraction_Phase  call Build_Heap to build the heap
Extract remove extreme item from location 1 of the array, 
move item in last location of the heap to location 1 and then call Heapify
this decreases the heap's size by 1
Size returns the number of items currently in the heap, not the array size