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:

  1. when i=1, for j<- 1 2n-1
    when i=2, for j<- 1 2n-2
    . . .
    when i=n, for j<- 1 2n-n

  2. when i=1, for j<- 2 n+1
    when i=2, for j<- 2 n+2
    . . .
    when i=n, for j<- 2 n+n


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -