Foundations
Linear Structures
Hashing
Array and String Patterns
Recursion, Search, and Sorting
Problem Solving Patterns
Algorithm Searching
Sorting Algorithms
Array Algorithms
Grid Algorithms
Linear Structure Algorithms
Hashing Algorithms
Recursion and Backtracking
Greedy Algorithms
Tree and Heap Algorithms
Graph Algorithms
Dynamic Programming Algorithms
String Algorithms
Math Algorithms
Keyboard ready
Space plays. Arrow keys step. R restarts.
LAB Heap Sort Lab
Sorting
Problem shape
Intermediate
4
8
15
16
23
42
Core idea
Build a heap, then repeatedly move the max value to the end.
Step 1 / 5
Problem shape
Sorting Intermediate
Heap Sort
Welcome to the Heap Sort algorithm lab. Build a heap, then repeatedly move the max value to the end. Use it when: Use when O(1) auxiliary space and guaranteed O(n log n) time are useful. The time complexity is O(n log n), and the space complexity is O(1). The pseudocode is: build max heap for end from n - 1 down to 1 swap heap[0], heap[end] heapify(0, end) As you practice, track the state that changes and the condition that makes the algorithm stop.
Time
O(n log n)
Space
O(1)
Pseudocode
build max heap
for end from n - 1 down to 1
swap heap[0], heap[end]
heapify(0, end) 1.0x