Is the time complexity of the empty algorithm O(0)?

后端 未结 14 2286
暗喜
暗喜 2020-12-12 21:29

So given the following program:


Is the time complexity of this program O(0)? In other words, is 0 O(0)?

I thought answering this in a separate question

14条回答
  •  臣服心动
    2020-12-12 22:11

    It should be O(1). The coefficient is always 1.

    Consider:

    If something grows like 5n, you don't say O(5n), you say O(n) [in other words, O(1n)]

    If something grows like 7n^2, you don't say O(7n^2), you say O(n^2) [in other words, O(1n^2)]

    Likewise you should say O(1), not O(some other constant)

提交回复
热议问题