Sorted or reversed
transcript
Here is one sort, on one thousand numbers. We give it three different orders of the same numbers. Then we count its comparisons by running it. The three counts are very different.
Start with a list that is already sorted. Each new item is in place after one comparison. Nine hundred ninety nine comparisons in all. This is the best case for insertion sort.
Now reverse the list, largest number first. Every item moves all the way to the left. That costs four hundred ninety nine thousand five hundred comparisons. This is the worst case, five hundred times the best.
Now shuffle the list, with seed seven. One run made two hundred fifty eight thousand nine hundred seventy five. That is about half of the worst case. A different shuffle gives a nearby, not identical, count.
Sorted is the best case. Reversed is the worst case. A shuffled list sits in between.
Always say which input you mean. Full breakdown in the lecture.