Big O notation for triangular numbers?

前端 未结 6 1673
春和景丽
春和景丽 2020-12-11 18:13

What\'s the correct big O notation for an algorithm that runs in triangular time? Here\'s an example:

func(x):
  for i in 0..x
    for j in 0..i
      do_som         


        
6条回答
  •  春和景丽
    2020-12-11 19:00

    Yeah, O(n^2) is definitly correct. If I recall correctly, O is anyway always an upper bound, so O(n^3) should IMO also be correct, as would O(n^n) or whatever. However O(n^2) seems to be the most tight one that is easily deductable.

提交回复
热议问题