formula for the sum of n+n/2+n/3+…+n/n
up vote
0
down vote
favorite
so I got this algorithm I need to calculate its time complexity
which goes like
for i=1 to n do
k=i
while (k<=n) do
FLIP(A[k])
k = k + i
where A
is an array of booleans, and FLIP is as it is, flipping the current value. therefore it's O(1)
.
Now I understand that the inner while loop should be called
n/1+n/2+n/3+...+n/n
If I'm correct, but is there a formula out there for such calculation?
pretty confused here
thanks!
algorithm math time-complexity calculus
add a comment |
up vote
0
down vote
favorite
so I got this algorithm I need to calculate its time complexity
which goes like
for i=1 to n do
k=i
while (k<=n) do
FLIP(A[k])
k = k + i
where A
is an array of booleans, and FLIP is as it is, flipping the current value. therefore it's O(1)
.
Now I understand that the inner while loop should be called
n/1+n/2+n/3+...+n/n
If I'm correct, but is there a formula out there for such calculation?
pretty confused here
thanks!
algorithm math time-complexity calculus
FLIP is O(1), I couldn't find the edit button for some reason :X, and I got the expression in the title by trying with a sample array of size 10, in the first iteration of the outer loop, the inner loop will iterate 10 times, in the second one the inner loop will iterate 5 times and the third time will iterate 3 times and so on..
– stylo
Nov 10 at 16:01
The edit button is right under your question. If you cannot find it, use your browser "search on page" function. For more info see Harmonic series.
– n.m.
Nov 10 at 16:12
1
@RoryDaulton, note thek = k + i
in the pseudo code (notk = k + 1
).
– trincot
Nov 10 at 16:13
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
so I got this algorithm I need to calculate its time complexity
which goes like
for i=1 to n do
k=i
while (k<=n) do
FLIP(A[k])
k = k + i
where A
is an array of booleans, and FLIP is as it is, flipping the current value. therefore it's O(1)
.
Now I understand that the inner while loop should be called
n/1+n/2+n/3+...+n/n
If I'm correct, but is there a formula out there for such calculation?
pretty confused here
thanks!
algorithm math time-complexity calculus
so I got this algorithm I need to calculate its time complexity
which goes like
for i=1 to n do
k=i
while (k<=n) do
FLIP(A[k])
k = k + i
where A
is an array of booleans, and FLIP is as it is, flipping the current value. therefore it's O(1)
.
Now I understand that the inner while loop should be called
n/1+n/2+n/3+...+n/n
If I'm correct, but is there a formula out there for such calculation?
pretty confused here
thanks!
algorithm math time-complexity calculus
algorithm math time-complexity calculus
edited Nov 10 at 16:13
asked Nov 10 at 15:50
stylo
458
458
FLIP is O(1), I couldn't find the edit button for some reason :X, and I got the expression in the title by trying with a sample array of size 10, in the first iteration of the outer loop, the inner loop will iterate 10 times, in the second one the inner loop will iterate 5 times and the third time will iterate 3 times and so on..
– stylo
Nov 10 at 16:01
The edit button is right under your question. If you cannot find it, use your browser "search on page" function. For more info see Harmonic series.
– n.m.
Nov 10 at 16:12
1
@RoryDaulton, note thek = k + i
in the pseudo code (notk = k + 1
).
– trincot
Nov 10 at 16:13
add a comment |
FLIP is O(1), I couldn't find the edit button for some reason :X, and I got the expression in the title by trying with a sample array of size 10, in the first iteration of the outer loop, the inner loop will iterate 10 times, in the second one the inner loop will iterate 5 times and the third time will iterate 3 times and so on..
– stylo
Nov 10 at 16:01
The edit button is right under your question. If you cannot find it, use your browser "search on page" function. For more info see Harmonic series.
– n.m.
Nov 10 at 16:12
1
@RoryDaulton, note thek = k + i
in the pseudo code (notk = k + 1
).
– trincot
Nov 10 at 16:13
FLIP is O(1), I couldn't find the edit button for some reason :X, and I got the expression in the title by trying with a sample array of size 10, in the first iteration of the outer loop, the inner loop will iterate 10 times, in the second one the inner loop will iterate 5 times and the third time will iterate 3 times and so on..
– stylo
Nov 10 at 16:01
FLIP is O(1), I couldn't find the edit button for some reason :X, and I got the expression in the title by trying with a sample array of size 10, in the first iteration of the outer loop, the inner loop will iterate 10 times, in the second one the inner loop will iterate 5 times and the third time will iterate 3 times and so on..
– stylo
Nov 10 at 16:01
The edit button is right under your question. If you cannot find it, use your browser "search on page" function. For more info see Harmonic series.
– n.m.
Nov 10 at 16:12
The edit button is right under your question. If you cannot find it, use your browser "search on page" function. For more info see Harmonic series.
– n.m.
Nov 10 at 16:12
1
1
@RoryDaulton, note the
k = k + i
in the pseudo code (not k = k + 1
).– trincot
Nov 10 at 16:13
@RoryDaulton, note the
k = k + i
in the pseudo code (not k = k + 1
).– trincot
Nov 10 at 16:13
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
The more exact computation is T(n) sum((n-i)/i)
for i = 1 to n
(because k
is started from i
). Hence, the final sum is n + n/2 + ... + n/n - n = n(1 + 1/2 + ... + 1/n) - n
, approximately. We knew 1 + 1/2 + ... + 1/n = H(n)
and H(n) = Theta(log(n)). Hence, T(n) = Theta(nlog(n))
. The -n
has anot any effect on the asymptotic computaional cost, as n = o(nlog(n))
.
I can't understand how the -n has anything to do with this formula? I understand how it got from this (n/1)+(n/2)+...+(n/n) to H(n) which is equal to ln(n) but also I need to multiply everything by n, so it comes to n*ln(n) isn't it?
– stylo
Nov 10 at 17:14
@stylo as I've mentioned becausen = o(nlog(n))
(o
meanslittle-oh
).
– OmG
Nov 10 at 18:33
add a comment |
up vote
0
down vote
Lets say we want to calculate sum of this equation
n + n / 2 + n / 3 + ... + n / n
=> n ( 1 + 1 / 2 + 1 / 3 + ..... + 1 / n )
Then in bracket ( 1 + 1 / 2 + 1 / 3 + ... + 1 / n ) this is a well known Harmonic series and i am afraid there is no proven formula to calculate Harmonic series.
1
There is a formula that expresses the asymptotic behaviour of the harmonic series, which is what OP mist likely needs.
– n.m.
Nov 10 at 19:49
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
The more exact computation is T(n) sum((n-i)/i)
for i = 1 to n
(because k
is started from i
). Hence, the final sum is n + n/2 + ... + n/n - n = n(1 + 1/2 + ... + 1/n) - n
, approximately. We knew 1 + 1/2 + ... + 1/n = H(n)
and H(n) = Theta(log(n)). Hence, T(n) = Theta(nlog(n))
. The -n
has anot any effect on the asymptotic computaional cost, as n = o(nlog(n))
.
I can't understand how the -n has anything to do with this formula? I understand how it got from this (n/1)+(n/2)+...+(n/n) to H(n) which is equal to ln(n) but also I need to multiply everything by n, so it comes to n*ln(n) isn't it?
– stylo
Nov 10 at 17:14
@stylo as I've mentioned becausen = o(nlog(n))
(o
meanslittle-oh
).
– OmG
Nov 10 at 18:33
add a comment |
up vote
2
down vote
The more exact computation is T(n) sum((n-i)/i)
for i = 1 to n
(because k
is started from i
). Hence, the final sum is n + n/2 + ... + n/n - n = n(1 + 1/2 + ... + 1/n) - n
, approximately. We knew 1 + 1/2 + ... + 1/n = H(n)
and H(n) = Theta(log(n)). Hence, T(n) = Theta(nlog(n))
. The -n
has anot any effect on the asymptotic computaional cost, as n = o(nlog(n))
.
I can't understand how the -n has anything to do with this formula? I understand how it got from this (n/1)+(n/2)+...+(n/n) to H(n) which is equal to ln(n) but also I need to multiply everything by n, so it comes to n*ln(n) isn't it?
– stylo
Nov 10 at 17:14
@stylo as I've mentioned becausen = o(nlog(n))
(o
meanslittle-oh
).
– OmG
Nov 10 at 18:33
add a comment |
up vote
2
down vote
up vote
2
down vote
The more exact computation is T(n) sum((n-i)/i)
for i = 1 to n
(because k
is started from i
). Hence, the final sum is n + n/2 + ... + n/n - n = n(1 + 1/2 + ... + 1/n) - n
, approximately. We knew 1 + 1/2 + ... + 1/n = H(n)
and H(n) = Theta(log(n)). Hence, T(n) = Theta(nlog(n))
. The -n
has anot any effect on the asymptotic computaional cost, as n = o(nlog(n))
.
The more exact computation is T(n) sum((n-i)/i)
for i = 1 to n
(because k
is started from i
). Hence, the final sum is n + n/2 + ... + n/n - n = n(1 + 1/2 + ... + 1/n) - n
, approximately. We knew 1 + 1/2 + ... + 1/n = H(n)
and H(n) = Theta(log(n)). Hence, T(n) = Theta(nlog(n))
. The -n
has anot any effect on the asymptotic computaional cost, as n = o(nlog(n))
.
answered Nov 10 at 16:04
OmG
7,28252643
7,28252643
I can't understand how the -n has anything to do with this formula? I understand how it got from this (n/1)+(n/2)+...+(n/n) to H(n) which is equal to ln(n) but also I need to multiply everything by n, so it comes to n*ln(n) isn't it?
– stylo
Nov 10 at 17:14
@stylo as I've mentioned becausen = o(nlog(n))
(o
meanslittle-oh
).
– OmG
Nov 10 at 18:33
add a comment |
I can't understand how the -n has anything to do with this formula? I understand how it got from this (n/1)+(n/2)+...+(n/n) to H(n) which is equal to ln(n) but also I need to multiply everything by n, so it comes to n*ln(n) isn't it?
– stylo
Nov 10 at 17:14
@stylo as I've mentioned becausen = o(nlog(n))
(o
meanslittle-oh
).
– OmG
Nov 10 at 18:33
I can't understand how the -n has anything to do with this formula? I understand how it got from this (n/1)+(n/2)+...+(n/n) to H(n) which is equal to ln(n) but also I need to multiply everything by n, so it comes to n*ln(n) isn't it?
– stylo
Nov 10 at 17:14
I can't understand how the -n has anything to do with this formula? I understand how it got from this (n/1)+(n/2)+...+(n/n) to H(n) which is equal to ln(n) but also I need to multiply everything by n, so it comes to n*ln(n) isn't it?
– stylo
Nov 10 at 17:14
@stylo as I've mentioned because
n = o(nlog(n))
(o
means little-oh
).– OmG
Nov 10 at 18:33
@stylo as I've mentioned because
n = o(nlog(n))
(o
means little-oh
).– OmG
Nov 10 at 18:33
add a comment |
up vote
0
down vote
Lets say we want to calculate sum of this equation
n + n / 2 + n / 3 + ... + n / n
=> n ( 1 + 1 / 2 + 1 / 3 + ..... + 1 / n )
Then in bracket ( 1 + 1 / 2 + 1 / 3 + ... + 1 / n ) this is a well known Harmonic series and i am afraid there is no proven formula to calculate Harmonic series.
1
There is a formula that expresses the asymptotic behaviour of the harmonic series, which is what OP mist likely needs.
– n.m.
Nov 10 at 19:49
add a comment |
up vote
0
down vote
Lets say we want to calculate sum of this equation
n + n / 2 + n / 3 + ... + n / n
=> n ( 1 + 1 / 2 + 1 / 3 + ..... + 1 / n )
Then in bracket ( 1 + 1 / 2 + 1 / 3 + ... + 1 / n ) this is a well known Harmonic series and i am afraid there is no proven formula to calculate Harmonic series.
1
There is a formula that expresses the asymptotic behaviour of the harmonic series, which is what OP mist likely needs.
– n.m.
Nov 10 at 19:49
add a comment |
up vote
0
down vote
up vote
0
down vote
Lets say we want to calculate sum of this equation
n + n / 2 + n / 3 + ... + n / n
=> n ( 1 + 1 / 2 + 1 / 3 + ..... + 1 / n )
Then in bracket ( 1 + 1 / 2 + 1 / 3 + ... + 1 / n ) this is a well known Harmonic series and i am afraid there is no proven formula to calculate Harmonic series.
Lets say we want to calculate sum of this equation
n + n / 2 + n / 3 + ... + n / n
=> n ( 1 + 1 / 2 + 1 / 3 + ..... + 1 / n )
Then in bracket ( 1 + 1 / 2 + 1 / 3 + ... + 1 / n ) this is a well known Harmonic series and i am afraid there is no proven formula to calculate Harmonic series.
answered Nov 10 at 17:54
Shakil
4391313
4391313
1
There is a formula that expresses the asymptotic behaviour of the harmonic series, which is what OP mist likely needs.
– n.m.
Nov 10 at 19:49
add a comment |
1
There is a formula that expresses the asymptotic behaviour of the harmonic series, which is what OP mist likely needs.
– n.m.
Nov 10 at 19:49
1
1
There is a formula that expresses the asymptotic behaviour of the harmonic series, which is what OP mist likely needs.
– n.m.
Nov 10 at 19:49
There is a formula that expresses the asymptotic behaviour of the harmonic series, which is what OP mist likely needs.
– n.m.
Nov 10 at 19:49
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240625%2fformula-for-the-sum-of-nn-2n-3-n-n%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
FLIP is O(1), I couldn't find the edit button for some reason :X, and I got the expression in the title by trying with a sample array of size 10, in the first iteration of the outer loop, the inner loop will iterate 10 times, in the second one the inner loop will iterate 5 times and the third time will iterate 3 times and so on..
– stylo
Nov 10 at 16:01
The edit button is right under your question. If you cannot find it, use your browser "search on page" function. For more info see Harmonic series.
– n.m.
Nov 10 at 16:12
1
@RoryDaulton, note the
k = k + i
in the pseudo code (notk = k + 1
).– trincot
Nov 10 at 16:13