What's the complexity of for i: for o = i+1

前端 未结 4 1295
难免孤独
难免孤独 2020-12-22 06:52
for i = 0 to size(arr)
   for o = i + 1 to size(arr)
      do stuff here

What\'s the worst-time complexity of this? It\'s not N^2, because the seco

4条回答
  •  死守一世寂寞
    2020-12-22 07:35

    It is N ^ 2, since it's the product of two linear complexities.

    (There's a reason asymptotic complexity is called asymptotic and not identical...)

    See Wikipedia's explanation on the simplifications made.

提交回复
热议问题