merge sort: O(n log n) always

Ever wondered why sorting your music library takes ages?

Image: Rob Glover from Bradford, UK, CC BY-SA 2.0, via Wikimedia Commons

merge sort: O(n log n) always

Ever wondered why sorting your music library takes ages?

Imagine you're organizing your favorite songs by genre and then by artist name, but the list keeps growing.

As you add more songs, the time to sort them increases. Merge sort divides the list and sorts each part before combining them, making it faster than just comparing every song.

Example

Sorting 1,000 songs takes longer than sorting 100 songs, but merge sort handles both efficiently.

Remember this

Merge sort's time complexity is O(n log n), meaning it consistently sorts lists faster as they grow.

Related concepts

Swipe through 100 ML concepts daily

Open Pocket Polymath