Browse curriculum

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.

10

Interactive lessons

3

Free to open

6

Languages (JS, TS, Python, Java, C, C++)

Lessons

Sorting lessons

Complexity

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.

LessonBestAverageWorstSpace
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 SortO(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 SortO(N + K)O(N + K)O(N + K)O(N + K)
Radix SortO(N*k)O(N*k)O(N*k)O(N + B)
Bucket SortΩ(n + k)Θ(n + k)O(n²)O(n + k)
Curriculum

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.

Directory

Every other DSA visualizer