How to resolve the algorithm Stirling numbers of the first kind step by step in the ALGOL W programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Stirling numbers of the first kind step by step in the ALGOL W programming language

Table of Contents

Problem Statement

Stirling numbers of the first kind, or Stirling cycle numbers, count permutations according to their number of cycles (counting fixed points as cycles of length one). They may be defined directly to be the number of permutations of n elements with k disjoint cycles. Stirling numbers of the first kind express coefficients of polynomial expansions of falling or rising factorials. Depending on the application, Stirling numbers of the first kind may be "signed" or "unsigned". Signed Stirling numbers of the first kind arise when the polynomial expansion is expressed in terms of falling factorials; unsigned when expressed in terms of rising factorials. The only substantial difference is that, for signed Stirling numbers of the first kind, values of S1(n, k) are negative when n + k is odd. Stirling numbers of the first kind follow the simple identities:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Stirling numbers of the first kind step by step in the ALGOL W programming language

Source code in the algol programming language

begin % show some (unsigned) Stirling numbers of the first kind              %
    integer MAX_STIRLING;
    MAX_STIRLING := 12;
    begin
        % construct a matrix of Stirling numbers up to max n, max n           %
        integer array s1 ( 0 :: MAX_STIRLING, 0 :: MAX_STIRLING );
        for n := 0 until MAX_STIRLING do begin
            for k := 0 until MAX_STIRLING do s1( n, k ) := 0
        end for_n ;
        s1( 0, 0 ) := 1;
        for n := 1 until MAX_STIRLING do s1( n, 0 ) := 0;
        for n := 1 until MAX_STIRLING do begin
            for k := 1 until n do begin
                integer s1Term;
                s1Term := ( ( n - 1 ) * s1( n - 1, k ) );
                s1( n, k ) := s1( n - 1, k - 1 ) + s1Term
            end for_k
        end for_n ;
        % print the Stirling numbers up to n, k = 12                          %
        write( "Unsigned Stirling numbers of the first kind:" );
        write( " k" );
        for k := 0 until MAX_STIRLING do writeon( i_w := 10, s_w := 0, k );
        write( " n" );
        for n := 0 until MAX_STIRLING do begin
            write( i_w := 2, s_w := 0, n );
            for k := 0 until n do begin
                writeon( i_w := 10, s_w := 0, s1( n, k ) )
            end for_k
        end for_n
    end
end.

  

You may also check:How to resolve the algorithm Zumkeller numbers step by step in the Nim programming language
You may also check:How to resolve the algorithm String interpolation (included) step by step in the Racket programming language
You may also check:How to resolve the algorithm Binary search step by step in the E programming language
You may also check:How to resolve the algorithm Find common directory path step by step in the Scala programming language
You may also check:How to resolve the algorithm Sequence of primes by trial division step by step in the Spin programming language