Sorting algorithms/Heapsort: Difference between revisions

From Rosetta Code
Content added Content deleted
(created task)
 
m (formatting)
Line 1: Line 1:
{{task|Sorting Algorithms}}{{Sorting Algorithm}}[[wp:Heapsort|Heapsort]] is an in-place sorting algorithm with worst case and average complexity of O(n*log(n)). The basic idea is to turn the array into a binary heap structure, which has the property that it allows efficient retrieval and removal of the maximal element. We repeatedly "remove" the maximal element from the heap, thus building the sorted list from back to front. See [[wp:Heapsort]] for more details and pseudocode. Heapsort requires random access, so can only be used on an array-like data structure.
{{task|Sorting Algorithms}}{{Sorting Algorithm}}[[wp:Heapsort|Heapsort]] is an in-place sorting algorithm with worst case and average complexity of <span style="font-family: serif">O(''n'' log''n'')</span>. The basic idea is to turn the array into a binary heap structure, which has the property that it allows efficient retrieval and removal of the maximal element. We repeatedly "remove" the maximal element from the heap, thus building the sorted list from back to front. See [[wp:Heapsort|Heapsort]] for more details and pseudocode. Heapsort requires random access, so can only be used on an array-like data structure.


Write a function to sort a collection of integers using heapsort.
Write a function to sort a collection of integers using heapsort.

Revision as of 09:47, 17 July 2009

Task
Sorting algorithms/Heapsort
You are encouraged to solve this task according to the task description, using any language you may know.

Heapsort is an in-place sorting algorithm with worst case and average complexity of O(n logn). The basic idea is to turn the array into a binary heap structure, which has the property that it allows efficient retrieval and removal of the maximal element. We repeatedly "remove" the maximal element from the heap, thus building the sorted list from back to front. See Heapsort for more details and pseudocode. Heapsort requires random access, so can only be used on an array-like data structure.

Write a function to sort a collection of integers using heapsort.