Chapter 3How Random Is That?
In the previous two chapters, we encountered a notable trade-off between Mergesort and Quicksort. On the one hand, Quicksort is the faster algorithm in average-case scenarios. On the other hand, Mergesort guarantees speedy sorting in all scenarios, while Quicksort slows down for arrays that already happen to be sorted. The trade-off is this: would you rather use an algorithm that is super fast in most scenarios but sometimes slow or an algorithm that is only moderately fast but guarantees that it’ll never be slow?
In this chapter, you’ll discover that this is a false dichotomy. We can use a technique called randomization to perform Quicksort so that it’s faster than Mergesort in all scenarios. You’ll likewise learn ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access