Heap sort using linked lists
The answer is "you don't want to implement heap sort on a linked list."
Heapsort is a good sorting algorithm because it's O(n log n)
and it's in-place. However, when you have a linked list heapsort is no longer O(n log n)
because it relies on random access to the array, which you do not have in a linked list. So you either lose your in-place attribute (by needing to define a tree-like structure is O(n)
space). Or you will need to do without them, but remember that a linked list is O(n)
for member lookup. Which brings the runtime complexity to something like O(n^2 log n)
which is worse than bubblesort.
Just use mergesort instead. You already have the O(n)
memory overhead requirement.