Time complexity for constant length loop

Viewed 1830

I am having a hard time deciding how to state the worst-case runtime complexity of a function within a class.

This class stores two kinds of objects, say N and M, possibly millions of them.

One of the operations just searches for the best place to store an item:

void foo(item) {
    for (int i=0;i<K;i++) {
        for (int j=i;j<K;j++) {
            if(store(i,j,item)) // store is O(1)
                return;
        }
    }
}

Here K, is a problem defined constant (say 10). In the worst case the item might not be stored and the loops will be exhausted.

I can't decide if it's more correct to say foo has O(1) complexity, as K is a given constant that doesn't depend on N and M; or it's better to say complexity is O(k2). Maybe even amortized O(1) ?

2 Answers
Related