We often find it useful to abbreviate a sum
with
.
We can view this as a little algorithm if we wish: Let us use
s to hold the above sum at the end of the program, and assume
that double[] a is an array holding the numbers we wish to
add, that is: a[i] =
.
double s=0;
for (i=1; i<=n; i++)
s = s + a[i];
The most common use of sums for our purposes is when investigating
the complexity of a program. For that, we usually have to count a
variant of
. Hence it is helpful to know that
In order to illustrate this, consider the program
for (i=0; i<n; i++)
{ for(j=0; j<=i; j++)
{ k++ //dummy instruction 1
l++ //dummy instruction 2
m++ //dummy instruction 3
}
}
By the above discussion, its complexity is given as follows: