You are on page 1of 3

2/2/2019 TADM2E 2.

2 - Algorithm Wiki

TADM2E 2.2
From Algorithm Wiki

f(n) = n(n+1)(n+2)/3

Step by step explanation:

This loop can be expressed as the sum:

n i i+j

∑∑∑1

i=1 j=1 k=j

Reducing this, sum by sum from the rhs:

http://www.algorist.com/algowiki/index.php/TADM2E_2.2 1/3
2/2/2019 TADM2E 2.2 - Algorithm Wiki

n i i+j

∑∑∑1 =

i=1 j=1 k=j

n i

∑∑i + j − j + 1 =

i=1 j=1

n i i
⎛ ⎞
∑ ∑i + ∑1 =
⎝ ⎠
i=1 j=1 j=1

n i i
⎛ ⎞
∑ i∑1 + ∑1 =
⎝ ⎠
i=1 j=1 j=1

n i
⎛ ⎞
∑ (i + 1) ∑ 1 =
⎝ ⎠
i=1 j=1

∑(i + 1)i =

i=1

2
∑i + i =

i=1

n n
2
∑i + ∑i =

i=1 i=1

n(n + 1)(2n + 1) (n − 1 + 1)(n + 1)


+ =
6 2

n(n + 1)(2n + 1) n(n + 1)


+ =
6 2

n(n + 1)(2n + 1) + 3n(n + 1)


=
6

n(n + 1)(2n + 1 + 3)
=
6

n(n + 1)(2n + 4)
=
6

2n(n + 1)(n + 2)
=
6

n(n + 1)(n + 2)

and order is O((n^3)/3)

Return to Algo-analysis-TADM2E ...

Retrieved from "http://algorist.com/algowiki/index.php?title=TADM2E_2.2&oldid=178"

http://www.algorist.com/algowiki/index.php/TADM2E_2.2 2/3
2/2/2019 TADM2E 2.2 - Algorithm Wiki

This page was last modified on 11 September 2014, at 18:23.


This page has been accessed 9,858 times.

http://www.algorist.com/algowiki/index.php/TADM2E_2.2 3/3

You might also like