Documentation of 'edu.princeton.cs.algs4.ThreeSum' Java class
ThreeSum
edu.princeton.cs.algs4

Class ThreeSum



  • public class ThreeSum
    extends java.lang.Object
    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.

    For additional documentation, see Section 1.4 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static int count(int[] a)
      Returns the number of triples (i, j, k) with i < j < k such that a[i] + a[j] + a[k] == 0.
      static void main(java.lang.String[] args)
      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.
      static void printAll(int[] a)
      Prints to standard output the (i, j, k) with i < j < k such that a[i] + a[j] + a[k] == 0.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • printAll

        public static void printAll(int[] a)
        Prints to standard output the (i, j, k) with i < j < k such that a[i] + a[j] + a[k] == 0.
        Parameters:
        a - the array of integers
      • count

        public static int count(int[] a)
        Returns the number of triples (i, j, k) with i < j < k such that a[i] + a[j] + a[k] == 0.
        Parameters:
        a - the array of integers
        Returns:
        the number of triples (i, j, k) with i < j < k such that a[i] + a[j] + a[k] == 0
      • main

        public static void main(java.lang.String[] args)
        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.
        Parameters:
        args - the command-line arguments

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.