Big O Notation of an expression

后端 未结 6 1659
南笙
南笙 2021-02-06 10:22

If I have an algorithm that takes 4n^2 + 7n moves to accomplish, what is its O? O(4n^2)? O(n^2)?

I know that 7n is cut off, but I don\'t know if I should keep the n^2 c

6条回答
  •  时光取名叫无心
    2021-02-06 11:04

    It's O(n^2). Constant factors "move into the O". You only keep the largest exponent since this is the one dominating. And you can leave out coefficients since when comparing different algorithms even very large coefficients result in smaller total numbers than having a larger exponent (with n large enough).

提交回复
热议问题