I'm reading Sedgewick's "Algorithms" and completely stuck at one exercise. It is formulated like that:
Develop an appropriate mathematical model describing the number of triples of N random int values that sum to 0, where the values are uniformly distributed between –M and M, where M is not small
I wrote a program to calculate such triplets. It iterates through all possible distinct triplets in array A of N numbers. A may have repeating numbers, but these numbers are form uniform random generator.
Example:
A = [7, -3, -4, 0] gives 4 distinct triplets: {7, -3, -4}, {7, -3, 0}, {7, -4, 0}, {-3, -4, 0}. We have only one triplet (first) that sums to 0.
I already calculated the number of 3-samples, it's sampling without replacement and without order: N! / 3! (N - 3)!, but I have no idea how to formulate quantity of triplets that sum to zero.
I want a model and mathematical basis, to calculate average quantity of such triplets among all 3-samples from N.