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 Push and Pop Lab
Trees
Problem shape
Intermediate
8
3
10
1
6
9
14
Core idea
Maintain the heap property by bubbling values up or down.
Step 1 / 5
Problem shape
Trees Intermediate
Heap Push and Pop
Welcome to the Heap Push and Pop algorithm lab. Maintain the heap property by bubbling values up or down. Use it when: Use for priority queues, scheduling, k-largest, and graph algorithms. The time complexity is O(log n), and the space complexity is O(1). The pseudocode is: push(value) append value bubble up while parent is larger pop() replace root with last bubble down As you practice, track the state that changes and the condition that makes the algorithm stop.
Time
O(log n)
Space
O(1)
Pseudocode
push(value)
append value
bubble up while parent is larger
pop()
replace root with last
bubble down 1.0x