The Sort vs Search tradeoff


Transcript:

So yesterday we saw that sorting does not have economies of scale. It takes a lot more effort to sort something as the number becomes bigger and bigger. There's no economies of scale.

So now it comes to an essential trade-off. Whether we should sort something or we should just search for it. How do you find something? Is it easier to find something that is sorted or just to search for it in an unsorted format?

If you account carefully for the time it takes for sorting versus searching, you'll realize very quickly that sorting simply is a preemptive measure to save effort in the future if you need to search for something.

And when you account for this, it turns out that it is better to err on the side of messiness. Keep things unsorted.

Because sorting and then never searching for something that you sorted is a complete waste of time. However, searching for something that you have not sorted is simply inefficient.

(Birds chirping)