Ever wonder why sorting can't be faster than a certain point?
Image: The Government of the Grand-Duchy of Luxembourg, Public domain, via Wikimedia Commons
Ever wonder why sorting can't be faster than a certain point?
Imagine you're organizing a bookshelf by height, but you can't compare books directly. You need to know the height of each book to place them correctly.
You're limited by how many times you can compare books to figure out their order. There's a minimum number of comparisons needed to sort them all.
Example
If you have 8 books and compare them in pairs, you might need up to 7 comparisons to sort them all.
Remember this
The lower bound for sorting is O(n log n) comparisons.
Text adapted from Wikipedia, licensed under CC BY-SA 4.0.
merge sort: O(n log n) always
Ever wondered why sorting your music library takes ages?
Binary search
How fast can you find a word in a dictionary?
B-trees optimize: disk-based sorted data with O(log n) reads per query
B-trees optimize disk-based sorted data with O(log n) reads per query
Best, worst and average case
Quicksort's average time complexity is O(n log n)
Dijkstra's algorithm
Dijkstra's algorithm time complexity: O((V+E) log V)
Hash table
Hash table lookup: O(1) average time complexity
Swipe through 100 ML concepts daily
Open Pocket Polymath