We are no longer accepting contributions to Documentation. Please see our post on meta.

algorithm

Integer Partition Algorithm

This draft deletes the entire topic.

Examples

  • -1

    The partition of an integer is a way of writing it as a sum of positive integers. For example, the partitions of the number 5 are:

    • 5
    • 4 + 1
    • 3 + 2
    • 2 + 2 + 1
    • 2 + 1 + 1 + 1
    • 1 + 1 + 1 + 1 + 1

    Notice that changing the order of the summands will not create a different partition.

    The partition function is inherently recursive in nature since the results of smaller numbers appear as components in the result of a larger number. Let p(n,m) be the number of partitions of n using only positive integers that are less than or equal to m. It may be seen that p(n) = p(n,n), and also p(n,m) = p(n,n) = p(n) for m > n.

    Equation

    Example of Integer Partition Algorithm:

    Example of Integer Partition Algorithm

    Auxiliary Space: O(n^2)
    Time Complexity: O(n(logn))

  • -1
     public class IntegerPartition
    {
        public static int[,] Result = new int[100,100];
    
        private static int Partition(int targetNumber, int largestNumber)
        {
            for (int i = 1; i <= targetNumber; i++)
            {
                for (int j = 1; j <= largestNumber; j++)
                {
                    if (i - j < 0)
                    {
                        Result[i, j] = Result[i, j - 1];
                        continue;
                    }
                    Result[i, j] = Result[i, j - 1] + Result[i - j, j];
                }
            }
            return Result[targetNumber, largestNumber];
        }
    
        public static int Main(int number, int target)
        {
            int i;
            for (i = 0; i <= number; i++)
            {
                Result[i, 0] = 0;
            }
            for (i = 1; i <= target; i++)
            {
                Result[0, i] = 1;
            }
            return Partition(number, target);
        }
    }
    
Please consider making a request to improve this example.

Syntax

Syntax

Parameters

Parameters

Remarks

Remarks

Still have a question about Integer Partition Algorithm? Ask Question

Topic Outline


    We are no longer accepting contributions to Documentation. Drafts cannot be modified.