What is the running time of the following program which counts the number of distinct triples in a given integer array of size n which sum to 0 (An application of this is to test collinearity of three points).
Assume input array a of size n is already given. (Using the idea from the second problem, can you make it more efficient - better than this algorithm).
cnt=0;
for (i=0;i<n;i++)
for (j=i+1;j<n;j++)
for (k=j+1;k<n;k++)
if (a[i]+a[j]+a[k]==0)
cnt++;