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

Автор question_id, история, 10 лет назад, По-английски

I could not understand the complexity of this series. N/1+N/2+N/3+N/4+.....+N/N.

cAN ANYONE EXPLAIN ME? tHANKS.

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

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +14 Проголосовать: не нравится

given series : N(1 + 1/2 + 1/3 + ... + 1/N) converges to N(log(N)). https://en.wikipedia.org/wiki/Harmonic_series_(mathematics)

»
10 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +7 Проголосовать: не нравится

Take n common, expression becomes : n * (1 + 1 / 2 + ... + 1/ n)

The expression (1 + 1 / 2 + 1 / 3 + ... 1 / n) is harmonic sum and it's bounded by ln(n). Hence overall complexity is O(n * logn).

Proof: Let us integrate 1 / x from 1 to n. (Note that we are doing integration, which means sum of area under the curve 1/x, which is greater than (1 + 1 / 2 + ... + 1 / n). Integration of 1/x dx is ln(x).