Half of all pivots are good.
transcript
The pivot decides the cost of quick sort. How often is a pivot a good one?
Take eight sorted values. A pivot is balanced if neither side is too big. Too big means more than three quarters. That is more than six of the eight.
The smallest value leaves seven on one side. The next value leaves six on one side. That is allowed. The values in the middle are all good. The largest value is bad, like the smallest.
Six of the eight choices are balanced. Only the two ends are bad. A random pick is good three times in four here.
Take a thousand distinct values. In one run, five hundred two choices were balanced. So a random pick is good about half the time.
A random pick does not look at the order. So sorted, reversed and random lists are all alike. Half are good, so the cost is n log n.
Pick the pivot at random. Full breakdown in the lecture.