Click or drag to resize
ThreeSumFast Class

The ThreeSumFast class provides static methods for counting and printing the number of triples in an array of distinct integers that sum to 0 (ignoring integer overflow).

This implementation uses sorting and binary search and takes time proportional to N^2 log N, where N is the number of integers.

Inheritance Hierarchy
SystemObject
  Algs4NetThreeSumFast

Namespace: Algs4Net
Assembly: Algs4Net (in Algs4Net.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
C#
public class ThreeSumFast

The ThreeSumFast type exposes the following members.

Methods
  NameDescription
Public methodStatic memberCount
Returns the number of triples (i, j, k) with i < j < k such that a[i] + a[j] + a[k] == 0.
Public methodStatic memberMainTest
Reads in a sequence of distinct 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.
Public methodStatic memberPrintAll
Prints to standard output the (i, j, k) with i < j < k such that a[i] + a[j] + a[k] == 0.
Top
Remarks
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 ThreeSumFast implementation by Robert Sedgewick and Kevin Wayne.

See Also