在Java中指定大O符号(算法)

huangapple go评论73阅读模式
英文:

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.

在Java中指定大O符号(算法)

答案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).

huangapple
  • 本文由 发表于 2020年10月22日 21:18:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/64483142.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定