r/AskComputerScience • • Apr 10 '26

What is average case complexity?

the average-case complexity of an algorithm is the amount of some computational resource (typically time) used by the algorithm, averaged over all possible inputs.

Aren't there infinite possible inputs? How does that make sense?

4 Upvotes

17 comments sorted by

View all comments

Show parent comment

1

u/ummaycoc May 04 '26

If you use the i'th order statistic algorithm you can always pick the median for quick sort and guarantee a O(n log n) worst case behavior. It just will be slow in real life on real data, but asymptotically optimal.