What is the complexity of this nested triple for loop?

后端 未结 5 1551
小蘑菇
小蘑菇 2020-12-14 22:55

I have searched a bit on StackOverflow and have understood the complexity up to the point of the j-loop, which is O(n2). However with the nested addi

5条回答
  •  醉酒成梦
    2020-12-14 23:46

    the k-loop has O(j-i) complexity

    the j-loop has O((n-i)*(n-i)) complexity

    the i-loop has O(n*n*n)=O(n^3) complexity

    anyway, you know that it is not O(n^2) because the first two loops are O(n^2) and it is not more than O(n^3) because there are only 3 loops

提交回复
热议问题