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?
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?
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)
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).