Big O notation for triangular numbers?

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

    The computation time increases by the factor of N*(N + 1)/2 for this code. This is essentially O(N^2).

提交回复
热议问题