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

2

u/jeffbell Apr 10 '26

It’s interesting to compare quicksort and bubble sort. 

They both have n-squared worst case behavior, however there are many common inputs to bubble sort that take n square time, but worst case input for quicksort is very rare. 

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.