2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,8 +1,13 @@
|
|||
{{Sorting Algorithm}} {{wikipedia|Heapsort}}
|
||||
{{omit from|GUISS}}
|
||||
[[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>.
|
||||
|
||||
<br>
|
||||
[[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.
|
||||
|
||||
Heapsort requires random access, so can only be used on an array-like data structure.
|
||||
|
||||
Pseudocode:
|
||||
|
|
@ -50,4 +55,7 @@ Pseudocode:
|
|||
root := child <span style="color: grey">''(repeat to continue sifting down the child now)''</span>
|
||||
'''else'''
|
||||
'''return'''
|
||||
|
||||
<br>
|
||||
Write a function to sort a collection of integers using heapsort.
|
||||
<br><br>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue