Блог пользователя oleksg

Автор oleksg, история, 3 года назад, По-английски

Sorry if this has already been answered before, I just couldn't find the answer anywhere.

  • Проголосовать: нравится
  • +8
  • Проголосовать: не нравится

»
3 года назад, # |
Rev. 3   Проголосовать: нравится +36 Проголосовать: не нравится

It's n times a partial sum of [harmonic series](https://en.wikipedia.org/wiki/Harmonic_series_(mathematics)#Partial_sums), so it's nlogn.

»
3 года назад, # |
Rev. 4   Проголосовать: нравится +14 Проголосовать: не нравится

If you meant that you want to get the complexity of computing this (with floor division), you can do so in $$$O(\sqrt n)$$$ by noting that there can be at most $$$2 \sqrt n$$$ distinct terms in the sum.

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

That's n(1/2 + 1/3 + ...) 1/2 + 1/3 + ... + 1/n is the harmonic series and equals with aproximative log(n). So the complexitate will be O(nlog(n))

»
3 года назад, # |
Rev. 2   Проголосовать: нравится +46 Проголосовать: не нравится

Here's how you can approximate that it is $$$nlogn$$$:
$$$\frac{n}{1} + \frac{n}{2} + ... + \frac{n}{n} = $$$
$$$n(\frac{1}{1} + \frac{1}{2} +\frac{1}{3}+ \frac{1}{4} + \frac{1}{5} + \frac{1}{6}+... +\frac{1}{n} \leq $$$
$$$ \leq n(\frac{1}{1} + \frac{1}{2} + \frac{1}{2} + \frac{1}{4} + \frac{1}{4} + \frac{1}{4} + \frac{1}{4} + \frac{1}{8} + \frac{1}{8} ... + \frac{1}{2^k} = $$$

$$$ = n(\frac{1}{1} + \frac{1}{2^1} + \frac{1}{2^1} + \frac{1}{2^2} + \frac{1}{2^2} + \frac{1}{2^2} + \frac{1}{2^2} + \frac{1}{2^3} + \frac{1}{2^3} ... + \frac{1}{2^k} $$$

$$$2^k \approx n \Rightarrow k \approx log_2n$$$
If we add all the components with the same power of 2, we get $$$1$$$. Because there are $$$\approx log_2n$$$ powers, we get that the sum is $$$\approx nlog_2n$$$

»
3 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

I didn't actually do this myself, but there's an interesting comment about bounding the harmonic numbers here. Jensen's inequality + some elementary calculus should do the trick (it's quite nice)

You can always bound with trapezoidal rule and some calc too, if you prefer

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

galen_colin explained it here here