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 Merge Sort Lab
Sorting
Problem shape
Intermediate
4
8
15
16
23
42
Core idea
Divide the array, sort each half, then merge sorted halves.
Step 1 / 5
Problem shape
Sorting Intermediate
Merge Sort
Welcome to the Merge Sort algorithm lab. Divide the array, sort each half, then merge sorted halves. Use it when: Use when stable sorting and predictable O(n log n) time matter. The time complexity is O(n log n), and the space complexity is O(n). The pseudocode is: sort(left, right) if left >= right return mid = (left + right) / 2 sort(left, mid) sort(mid + 1, right) merge(left, mid, right) As you practice, track the state that changes and the condition that makes the algorithm stop.
Time
O(n log n)
Space
O(n)
Pseudocode
sort(left, right)
if left >= right return
mid = (left + right) / 2
sort(left, mid)
sort(mid + 1, right)
merge(left, mid, right) 1.0x