Heapsort
The heapsort is a very dependable in-place sorting algorithm, with a rate of growth of [s]O[/s] (n log n). Though not quite as fast as quicksort, it has no worst-case scenario.
- Sort the complete binary tree (actually an array) so that it becomes a max-heap, thus the first element is always the biggest element.
- Since what we want is exactly the opposite (the last element should be the biggest instead), we swap the first element and the last element.
- Now we have to re-sort the array (except the last element), so that the first element is again the biggest.
- Then we repeat the second step, so that the first element is swapped with the current last element.
- We repeat 2, 3 so that all the elements are sorted.
Below is the pseudo-code of Heap Sort.
Heap Sort(Sorting array A[size])
For each parent node,
{
if there is any child node, we compare it with bigger child. If the parent
is less, we walk down the parent until none of its new children nodes are
greater.
}
While we do not reach the first cell,
{
swap the first cell with the last cell.
Change the last cell index to the cell preceding the last cell.
Walk down the first cell until none of its new children nodes are greater.
}
Related Tutorials
Balancing Game Development and Creative Direction in Indie Production
A practical look at how indie developers can balance creative direction with hands-on game development. This article co…
My Unreal Engine Development Process: From Core Idea to Playable Build
A practical overview of my Unreal Engine development process, covering how I move from a core game idea to a playable b…
Introducing LaneGraph: The Ultimate Road Network Solution for Unity
Discover the power of LaneGraph, a lightweight and flexible lane-based navigation system for Unity. LaneGraph makes it…
Retargeting Mixamo Characters with Root Motion In Unreal Engine 5.4.
I have always found Retargeting Mixamo Characters To have Root Motion is a serious lengthy Tast, Recently I stumbled up…
How To Make A SIMPLE Main Menu In Unity
In this tutorial for unity, i go over how to make a simple main menu for unity, it's an unlisted video because i do not…
Guide to Gameplay Balance
A perspective on competitive gameplay balance, from a background of "shooter" sandbox design.
Discussion
More from Yin-So Chen
Comparing Shadow Mapping Techniques with Shadow Explorer
New Incentives and a Whole New Platform From The Intel AppUp developer program
The final installment in this series on Intel's AppUp program details additional incentives and opportunities for devel…
The Game Maker
This book excerpt contains the first chapter of the book that introduces beginning game developers to the Game Maker pr…
Discussion