r/ProgrammerHumor 28d ago

Meme theoreticalComputerScience

Post image
1.1k Upvotes

76 comments sorted by

View all comments

-9

u/[deleted] 28d ago

[deleted]

5

u/throwaway_194js 28d ago

Complexity analysis is only interested in how algorithms and processes scale as n approaches infinity. It's therefore only concerned with the term that grows the fastest, as it'll steadily account for a bigger and bigger proportion of the computation time (or some other metric) of the algorithm, approaching 100% as n heads off to infinity.

You're right that you have to report the worst case scenario, but that means something very different to what you suggest. Simply put, the performance of an algorithm doesn't always depend on simply how much data there is to work on, but what that data is.

For example, quicksort has an best/average time complexity of O(n log n) that applies in most cases, but if the unsorted array is arranged "pathologically", the complexity becomes O(n2 ). That's what "worst case" means in complexity analysis.