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 Heaps and Priority Queues Lab
Trees
Concept shape
Core
Definition
A heap keeps the highest or lowest priority item at the top.
Step 1 / 5
Concept shape
Trees Core
Heaps and Priority Queues
Welcome to the Heaps and Priority Queues concept lab. A heap keeps the highest or lowest priority item at the top. The must know points are: Peek is O(1). Push and pop are O(log n). Priority queues are usually implemented with heaps. The common operations are: peek O(1), push O(log n), pop O(log n). The complexity shape is Push/pop O(log n), peek O(1). Watch out for these pitfalls: Expecting the whole heap array to be sorted. Using a normal queue when priorities matter. Related algorithms include Heap Sort, Dijkstra Shortest Path.
Concept details
A heap keeps the highest or lowest priority item at the top.
Must know
- Peek is O(1).
- Push and pop are O(log n).
- Priority queues are usually implemented with heaps.
Complexity
Push/pop O(log n), peek O(1)
1.0x