Heap Sort: Difference between revisions
From charlesreid1
(Created page with "Heaps are data structures with weak sorting - that is, the item at the root node is always guaranteed to be the minimum element, but the only invariant in a heap is that any c...") |
|||
| Line 9: | Line 9: | ||
This takes about O(N log N) time. | This takes about O(N log N) time. | ||
==Fast Heap Construction== | ==Fast, Bottom-Up Heap Construction== | ||
We can construct things faster by | We can construct things faster, from O(N log N) to O(N), by utilizing a bottom-up construction process. | ||
==Heap Sort Pseudocode== | ==Heap Sort Pseudocode== | ||
Revision as of 19:31, 26 July 2017
Heaps are data structures with weak sorting - that is, the item at the root node is always guaranteed to be the minimum element, but the only invariant in a heap is that any child node must be smaller than its parent.
Heaps are used in priority queues to keep items in a sorted order. But heaps are also useful for general sorting purposes. The heap sort algorithm starts by constructing a heap (tree data structure) and linking each heap node to a particular element in the original data. Once the heap is constructed, the algorithm removes items one at a time from the root node, and puts them in their final sorted position.
Heap Construction
There are several ways to construct a heap. The "normal" or naive way is to continually add nodes at the root. This bubbles nodes down the tree until they reach the correct final position.
This takes about O(N log N) time.
Fast, Bottom-Up Heap Construction
We can construct things faster, from O(N log N) to O(N), by utilizing a bottom-up construction process.
Heap Sort Pseudocode
Flags
| Trees Part of Computer Science Notes
Series on Data Structures Abstract data type: Trees/ADT Concrete implementations: Trees/LinkedTree · Trees/ArrayTree · SimpleTree
Tree Traversal Preorder traversal: Trees/Preorder Postorder traversal: Trees/Postorder In-Order traversal: Binary Trees/Inorder Breadth-First Search: BFS Breadth-First Traversal: BFT Depth-First Search: DFS Depth-First Traversal: DFT OOP Principles for Traversal: Tree Traversal/OOP · Tree Traversal/Traversal Method Template Tree operations: Trees/Operations Performance · Trees/Removal
Tree Applications Finding Minimum in Log N Time: Tree/LogN Min Search
Abstract data type: Binary Trees/ADT Concrete implementations: Binary Trees/LinkedBinTree · Binary Trees/ArrayBinTree Binary Trees/Cheat Sheet · Binary Trees/OOP · Binary Trees/Implementation Notes
|