Sorting
Sorting Algorithm Visualizer
Sorting is the classic visualization subject for a good reason: the entire algorithm is visible in the movement of the data. The difference between an O(n²) and an O(n log n) sort is not a fact to be recalled, it is something you can watch happen on the same input.
This topic covers the comparison sorts and the non-comparison sorts, which is the distinction interviewers probe when they ask whether you can do better than n log n. Stepping through counting and radix sort makes the answer concrete — they are faster because they never compare two elements at all.
Interactive lessons
Free to open
Languages (JS, TS, Python, Java, C, C++)
Sorting lessons
Sorting time and space complexity compared
Best, average and worst-case running time and extra space for every sorting lesson, as each lesson derives them.
| Lesson | Best | Average | Worst | Space |
|---|---|---|---|---|
| Bubble Sort | Ω(n) | Θ(n²) | O(n²) | O(1) |
| Selection Sort | Ω(N²) | Θ(N²) | O(N²) | O(1) |
| Insertion Sort | Ω(N) | Θ(N²) | O(N²) | O(1) |
| Merge Sort | Ω(N log N) | Θ(N log N) | O(N log N) | O(N) |
| Quick Sort | Ω(N log N) | Θ(N log N) | O(N²) | O(log N) |
| Heap Sort | O(N log N) | O(N log N) | O(N log N) | O(1) |
| Shell Sort | Ω(N log N) | Θ(N^1.5) | O(N²) | O(1) |
| Counting Sort | O(N + K) | O(N + K) | O(N + K) | O(N + K) |
| Radix Sort | O(N*k) | O(N*k) | O(N*k) | O(N + B) |
| Bucket Sort | Ω(n + k) | Θ(n + k) | O(n²) | O(n + k) |
Continue the DSA curriculum
Sorting is one of 12 topics in the interactive DSA visualizer curriculum. Once this topic is comfortable, the coding interview pattern library reorganises the same material around the patterns interview questions are built on.
Every other DSA visualizer
Data Structures · 28 lessons
- StackFree
- QueueFree
- Deque
- Circular Queue
- Priority Queue (ADT)
- Tree Traversal
- Binary Tree
- Binary Search Tree
- AVL Tree
- Trie (Prefix Tree)
- Segment Tree
- Fenwick Tree
- Red-Black Tree
- Singly Linked List
- Doubly Linked List
- Circular Linked List
- Graph RepresentationFree
- Breadth First SearchFree
- Depth First Search
- Topological Sort
- Cycle Detection
- Connected Components
- Bipartite Graph
- Dijkstra's Algorithm
- Bellman-Ford Algorithm
- Minimum Spanning Tree
- Floyd-Warshall Algorithm
- Bridges & Articulation Points
