algorithm - first and last terms of a nested loop, sums of arithmetic series starting with non zero index -
i have 2 arithmetic series...
(i) i<- 1 n j<- 1 2n-i //a unit cost operation
so first term 2n-1, last term 2n-n = n
(ii) <- 1 n j <- 2 (n+i) // unit cost operation
so similarly, first term n+1-1 = n, last term n+n-1 = 2n-1 ?
where minus 1 above come ? because index starts 2 ?
edit: previous question shows interested in number of terms in inner summation. loop for j<- first last
has last-first+1
terms (this easiest see if write down examples small last-first
). (1), there (2n-i)-(1)+1=2n-i
terms each i
. (2), there (n+i)-(2)+1=n+i-1
terms each i
.
you add according limits series specify themselves:
when
i=1
,for j<- 1 2n-1
wheni=2
,for j<- 1 2n-2
. . .
wheni=n
,for j<- 1 2n-n
when
i=1
,for j<- 2 n+1
wheni=2
,for j<- 2 n+2
. . .
wheni=n
,for j<- 2 n+n
Comments
Post a Comment