4 ms·
That would be nice to know, but Big-O won't tell you that. It makes no time guarantees, it only provides an idea of an implementation. An O(1) algorithm sounds
by hellofunk 10y ago
That would be nice to know, but Big-O won't tell you that. It makes no time guarantees, it only provides an idea of an implementation. 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.
What's in the parenthesis is not a measure of a unit of time, which is why Big-O fanatics often miss the bigger picture.
- 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?