|
|
|
|
|
by ot
782 days ago
|
|
> This function is O(1) I think I addressed that in my comment, but to be more explicit, this function is O(1) too: size_t find_sorted(void* object, void** list, size_t size) {
for (size_t i = 0; i < SIZE_MAX; ++i) {
if (i < size && list[i] > object) return i;
}
return SIZE_MAX;
}
If O(1) cannot distinguish your function from this function, what is its informational value?> Asymptotic bounds are useful when your input can grow arbitrarily large But your inputs can't grow arbitrarily large, that's why you can hardcode 3 levels. O(1) is an asymptotic bound, and my point is that it is not very informative here. |
|
The original poster said they wanted a O(1) solution to a problem. I presented one. That solution happens to be based on a data structure whose algorithms are, in the general case, O(log n). But we're not dealing with a general case, we're dealing with a specific case. And because of that specific case, we can write algorithms that are O(1). Unlike your example, these algorithms have a very small n; 3, to be exact. That is meaningful to describe as O(1) in this case because we can reduce the work down to a small constant.