> Finds all pairs of elements whose sum is 25
You can try to sort them first:
1. Sort the list - you can do it in O(n log n)
2.
j = n - 1;
for (i = 0; i < n - 1; i++)
{
for (; j > i; j--)
if (data[i] + data[j] == 25)
report(i, j);
else if (data[i] + data[j] < 25)
break;
if (data[i] + data[i+1] > 25)
break;
}
> Find the number EVNUM of elements of A which are even, and the number ODNUM of elements of A which are odd
It's a linear task. Can't think of optimization unless some low level involved.