Big O notation for triangular numbers?

前端 未结 6 1665
春和景丽
春和景丽 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:01

    If you think about it mathematically, the area of the triangle you are computing is ((n+1)^2)/2. This is therefore the computational time: O(((n+1)^2)/2)

提交回复
热议问题