Unit 07

Sorting Techniques

Putting data in order sounds simple, but the method you choose can mean the difference between milliseconds and minutes once the dataset gets large.

unsorted sorted same four values, rearranged into increasing order

// different algorithms reach this same end state at very different speeds

What it is

Sorting rearranges a collection into a defined order, usually ascending or descending. There's no single "best" algorithm — the right choice depends on the data size, whether it's mostly sorted already, and whether you need to sort in place.

Common approaches

Where the simple ones struggle

Time complexity

AlgorithmBestAverageWorst
Bubble sortO(n)O(n²)O(n²)
Insertion sortO(n)O(n²)O(n²)
Merge sortO(n log n)O(n log n)O(n log n)
Quick sortO(n log n)O(n log n)O(n²)

Quick check

← Hashing Next: Searching Techniques →