ThreeSum Class |
The ThreeSum class provides static methods for counting and printing the number of triples in an array of integers that sum to 0 (ignoring integer overflow).
This implementation uses a triply nested loop and takes proportional to N^3, where N is the number of integers.
Namespace: Algs4Net
public class ThreeSum
The ThreeSum type exposes the following members.
Name | Description | |
---|---|---|
![]() ![]() | Count |
Returns the number of triples (i, j, k) with i < j < k such that a[i] + a[j] + a[k] == 0. |
![]() ![]() | MainTest |
Reads in a sequence of integers from a file, specified as a command-line argument;
counts the number of triples sum to exactly zero; prints out the time to perform
the computation. |
![]() ![]() | PrintAll |
Prints to standard output the (i, j, k) with i < j < k such that
a[i] + a[j] + a[k] == 0. |
For additional documentation, see Section 1.4 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
This class is a C# port from the original Java class ThreeSum implementation by the respective authors.