com.graphbuilder.math.PascalsTriangle Class Reference

PascalsTriangle can be used for O(1) lookup of the nCr function. More...

List of all members.

Static Public Member Functions

static synchronized double nCr (int n, int r)
 The nCr function returns the number of ways r things can be chosen from a set of size n.
static synchronized void reset ()
 Resets the internal array to the initial state to free up memory.

Private Member Functions

 PascalsTriangle ()

Static Private Attributes

static double[][] pt = new double[][] { {1} }

Detailed Description

PascalsTriangle can be used for O(1) lookup of the nCr function.

Definition at line 6 of file PascalsTriangle.java.


Constructor & Destructor Documentation

com.graphbuilder.math.PascalsTriangle.PascalsTriangle (  )  [private]

Definition at line 8 of file PascalsTriangle.java.


Member Function Documentation

static synchronized double com.graphbuilder.math.PascalsTriangle.nCr ( int  n,
int  r 
) [static]

The nCr function returns the number of ways r things can be chosen from a set of size n.

Mathematically, it is defined as: n! / (r! * (n - r)!) Although the result is always a whole number, double precision is used because the maximum value a double can represent is larger than long. Thus, large returned values will only be an approximation of the actual value. If the result exceeds the capabilities of double precision then the result can be checked using Double.isInfinite(...). For example: System.out.println(PascalsTriangle.nCr(1030, 515)); // outputs: Infinity If the value of n or r is less than 0 or the value of r is greater than n then 0 is returned.

Definition at line 23 of file PascalsTriangle.java.

References com.graphbuilder.math.PascalsTriangle.pt.

static synchronized void com.graphbuilder.math.PascalsTriangle.reset (  )  [static]

Resets the internal array to the initial state to free up memory.

Definition at line 64 of file PascalsTriangle.java.

References com.graphbuilder.math.PascalsTriangle.pt.


Member Data Documentation

double [][] com.graphbuilder.math.PascalsTriangle.pt = new double[][] { {1} } [static, private]

The documentation for this class was generated from the following file:

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1