Given a list of N integers, the 3-sum problem is to determine whether there exists 3 integers in the list (not necessarily distinct) such that x + y + z = 0. Suppose that you are executing the brute force algorithm below on a computer that executes 1 billion operations (addition, increment, or comparison) per second. int brute
int brute(int a[], int N)
{
int i, j, k;
for (i = 0; i < N; i++)
for (j = 0; j < N; j++)
for (k = 0; k < N; k++)
if (a + a[j] + a[k] == 0) return 1;
return 0; // none found
}
Estimate how many seconds it will take (in the worst case) to solve a problem of size N = 1,000?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.