Which formula to be used for calculating no of iterations?

36 Views Asked by At

I wanted to perform a comparison against 8000 data.

  • To be more clear, my 1st data has to be compared with the rest of 7999 data and not within itself (i.e not 1st data against 1st data).
  • Similarly if 1st data is compared against 2nd data, I will not be performing the comparison against 2nd data against 1st data again.
  • This base applies for all the data.

Now I would like to find the actual comparison count for 8000 data. Which formula can be applied to get the needed result?

1

There are 1 best solutions below

0
On

It seems that you are looking for $$\sum_{i=1}^{n-1} \sum_{j=i+1}^n 1=\sum_{i=1}^{n-1}(n-i)=\frac 12 n(n-1)$$ which is the half of the number of terms in an $n \times n $ matrix (excluding the diagonal part since you do not compare $k$ against $k$).