0

I suppose it's possible to have a time complexity such as n-1, n-2, etc.

But is it possible to have an algorithm with, let's say, O(1/n) time, or even space complexity?

Da Mike
  • 378
  • 2
  • 13
  • 3
    Possible duplicate of [Are there any O(1/n) algorithms?](http://stackoverflow.com/questions/905551/are-there-any-o1-n-algorithms) – Paul Hankin Jun 09 '16 at 09:36

2 Answers2

2

You can't go below O(1) in complexity.

O(0) is undefined => can't have zero/instant cost operations and O(c) = O(1).

And in fact O(n-1) = O(n-2) = ... = O(n-c) = O(n)

Tamas Ionut
  • 3,932
  • 5
  • 31
  • 57
0

Assume you have a function f(n) you can compute in constant time, the time complexity of

procedure comp(n)
  for i=1 to f(n) do
    some computation in O(1)

will be in O(f(n)). You can build an algorithm with a O(1/n) time complexity → take f(n)=1000/n.

As f is a positive function, if f is monotonically decreasing then f must have a constant limit toward +oo and in fact such we would have O(f(n))⊆O(1).

Picodev
  • 456
  • 3
  • 7