Class Stirling

    • Method Detail

      • stirlingS1

        public static long stirlingS1​(int n,
                                      int k)
        Returns the signed Stirling number of the first kind, "s(n,k)". The number of permutations of n elements which contain exactly k permutation cycles is the nonnegative number: |s(n,k)| = (-1)^(n-k) s(n,k)
        Parameters:
        n - Size of the set
        k - Number of permutation cycles (0 <= k <= n)
        Returns:
        s(n,k)
        Throws:
        IllegalArgumentException - if n < 0, k < 0 or k > n.
        ArithmeticException - if some overflow happens, typically for n exceeding 20 (s(n,n-1) is handled specifically and does not overflow)
      • stirlingS2

        public static long stirlingS2​(int n,
                                      int k)
        Returns the Stirling number of the second kind, "S(n,k)", the number of ways of partitioning an n-element set into k non-empty subsets.
        Parameters:
        n - Size of the set
        k - Number of non-empty subsets (0 <= k <= n)
        Returns:
        S(n,k)
        Throws:
        IllegalArgumentException - if n < 0, k < 0 or k > n.
        ArithmeticException - if some overflow happens, typically for n exceeding 25 and k between 20 and n-2 (S(n,n-1) is handled specifically and does not overflow)