I have forgotten

• https://me.yahoo.com
COST (GBP)
2.09
0.19
0

# Partition

Computes the partition generated by the given permutation.
Controller: CodeCogs
Contents

C++

## Partition

 std::vectorpartition( int n int* p )
The problem of finding the partition of the set $\inline&space;&space;\{&space;1,&space;2,&space;\ldots,&space;n&space;\}$ generated by a certain permutation $\inline&space;&space;\sigma$ is the same with finding its disjoint cycle decomposition. Therefore, each cycle would represent a subset of the original set. This function returns a C++ vector with the property that $\inline&space;&space;v[i]&space;=&space;j$ if and only if $\inline&space;&space;i$ belongs to the subset of order $\inline&space;&space;j$. For instance, consider the following permutation:

$\sigma&space;=&space;\left(&space;\begin{array}{ccccccccc}&space;1&space;&&space;2&space;&&space;3&space;&&space;4&space;&&space;5&space;&&space;6&space;&&space;7&space;&&space;8&space;&&space;9&space;\cr&space;2&space;&&space;3&space;&&space;9&space;&&space;6&space;&&space;7&space;&&space;8&space;&&space;5&space;&&space;4&space;&&space;1&space;\end{array}&space;\right)$

then the vector $\inline&space;&space;v$ would be

$v&space;=&space;(1,&space;1,&space;1,&space;2,&space;3,&space;2,&space;3,&space;2,&space;1)$

generating the following partition

$[9]&space;=&space;\{2,&space;3,&space;9,&space;1\}&space;\cup&space;\{6,&space;8,&space;4\}&space;\cup&space;\{7,&space;5\}$

## Example:

#include <codecogs/maths/combinatorics/permutations/partition.h>
#include <iostream>
int main()
{
int tau[9] = {2, 3, 9, 6, 7, 8, 5, 4, 1};
std::vector<int> result = Maths::Combinatorics::Permutations::partition(9, tau);
std::cout << "The partition of the [9] set induced by the Tau permutation is:";
std::cout << std::endl;
for (int i = 1; i <= 9; i++)
{
for (int j = 0; j < 9; j++)
if (result[j] == i)
{
std::cout << "Subset " << i << " : { ";
for (; j < 9; j++)
if (result[j] == i)
std::cout << tau[j] << " ";
std::cout << "}" << std::endl;
}
}
return 0;
}

## Output:

The partition of the [9] set induced by the Tau permutation is:
Subset 1 : { 2 3 9 1 }
Subset 2 : { 6 8 4 }
Subset 3 : { 7 5 }

## References:

SUBSET, a C++ library of combinatorial routines, http://www.csit.fsu.edu/~burkardt/cpp_src/subset/subset.html

### Returns

the partition generated by the given permutation, with the property stated in the documentation

### Authors

Lucian Bentea (August 2005)
##### Source Code

Source code is available when you agree to a GP Licence or buy a Commercial Licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.