3 ms·
>An O(1) algorithm sounds great, until you realize that 1 means 1 hour for that particular algorithm, while a competing algorithm's O(n) might mean n seconds in
by tscs37 10y ago
>An O(1) algorithm sounds great, until you realize that 1 means 1 hour for that particular algorithm, while a competing algorithm's O(n) might mean n seconds in reality.
Well, I'm not trying to miss the bigger picture, but if you're going to scale that your O(n) algorithm will quickly take longer than a O(1) algorithm.
I mean, let's just take a hashtable as example. This hash takes 1 hour to complete while you can search the list in milliseconds.
But what if the list has billions and billions of entries and it takes longer than 1 hour?
As some others said, Big-O is not something you use to choose one algorithm over the other, it's something you use to choose an algorithm that scales well and has acceptable performance.
O(n) vs O(1) is a rather tame comparison, what if your competing algorithm is a O(n!) or worse?