英文:
Specifying Big-O notation in java (algorithms)
问题
我在充分理解大O符号方面有些困惑,希望能在提供的图片中获得以下问题的一些指导。对于第一个问题,我得出了O(n^2)的答案,但对我的答案并不十分有信心。任何帮助都将不胜感激。
英文:
I am struggling in fully understanding big-o notation, and would appreciate some guidance with the following questions in the image provided.
I have an answer of O(n^2) for the first question, however i am not fully confident in my answer. Any help would be great thanks.
答案1
得分: 4
在第一个问题中,复杂度为O(log5N),即O(log N)
,因为迭代次数受到条件5^N
的限制。另外注意,在第一个问题中计算的是一个“乘积”,而不是“和”。
在第二个问题中,迭代次数为(N - 5) * (2 * N) * 1000
,大约相当于2000 * N^2
,因此大O表示为O(N^2)
。
英文:
In the first question the complexity is O(log<sub>5</sub>N), that is, it is O(log N)
, as the number of iterations is limited by a condition 5^N
. Aside comment, in the first question a product
is calculated, not a sum
.
In the second question the number of iterations is (N - 5) * (2 * N) * 1000
, which is roughly equal to 2000 * N^2
, so big-O is O(N^2)
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论