Quicksort

Can sorting be faster than you think?

Quicksort

Can sorting be faster than you think?

Imagine you're organizing a bookshelf with thousands of books. Finding the quickest way to sort them by height without moving too many books around is crucial.

Quicksort picks a book as a 'pivot' and sorts the rest into shorter and taller piles, then sorts those piles themselves. This process repeats until all books are sorted.

Example

You have 100 books. Pick one as a pivot, and you end up with 49 shorter and 51 taller piles. Sort those piles, and you're closer to a sorted shelf.

Remember this

Quicksort's average-case speed is O(n log n), making it efficient for large collections.

Related concepts

Swipe through 100 ML concepts daily

Open Pocket Polymath