That’s what a new video from the TED-Ed YouTube channel does, by showing how different sorting algorithms can transform our ability to quickly alphabetize a large number of books on a bookshelf.
The video starts by describing two common sorting algorithms; “bubble sort” and “insertion sort.” In the former, a sorting algorithm repeatedly steps through a list that needs to be sorted, compares each pair of adjacent items in turn, and then swaps them over if they happen to be in the wrong order. In the latter, new items are constantly “inserted” into previous sublists for an ever-growing search pile.
Both will work for this problem, but are less than efficient if time is of the essence.
The optimal answer, it turns out, is something called “quicksort,” which is regularly used by programmers for a variety of different applications — from sorting items by price to showing you the closest gas station on a GPS map.
To sort your pile of books the quicksort way, begin by taking a book from roughly the middle of the shelf. This becomes your “partition” book, and by sorting everything on its left and right into books which come either before or after it, you instantly reduce the total number of items to search against in sub-piles.
Once this is done, you then add partition books to the middle section of the two smaller piles, and then keep doing this until you have multiple partition books and a bunch of manageable piles to sort. After that, switch to a sorting algorithm like “insertion sort” to get them properly alphabetized.
Simple, right? Sure, it’s a pretty basic bit of computer science translated into the real world, but we bet that you’ll never think about alphabetizing in quite the same way again.
Now if we could only stop spending hours watching such “life hack” videos, we might actually get something done a bit more efficiently around here!