I have forgotten

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

# Inversion Sequence

Computes the inversion sequence of a permutation.
Controller: CodeCogs

C++

## Inversion Sequence

 std::vectorinversion_sequence( int n int* p )
For a given permutation

$\sigma&space;=&space;\left(&space;\begin{array}{cccc}&space;1&space;&&space;2&space;&&space;\ldots&space;&&space;n&space;\cr&space;\sigma(1)&space;&&space;\sigma(2)&space;&&space;\ldots&space;&&space;\sigma(n)&space;\end{array}&space;\right)$

the inversion sequence $\inline&space;&space;(&space;\alpha&space;)$ is defined as

$\alpha(i)&space;=&space;\mathrm{card}&space;\{&space;j&space;<&space;i&space;|&space;\sigma(i)&space;<&space;\sigma(j)&space;\},&space;\quad&space;\forall&space;i&space;=&space;\overline{1,&space;n}$

with $\inline&space;&space;\alpha(1)&space;=&space;0$.

This function calculates the inversion sequence of a permutation based on the above formula and returns its value as a C++ vector object.

## Example:

#include <codecogs/maths/combinatorics/permutations/inversion_sequence.h>
#include <iostream>
int main()
{
int sigma[5] = {3, 5, 1, 4, 2};
std::vector<int> result = Maths::Combinatorics::Permutations::inversion_sequence(5, sigma);
std::cout << "The inversion sequence of the Sigma permutation: ";
std::cout << std::endl;
for (int i = 0; i < 5; i++)
std::cout << result[i] << "  ";
std::cout << std::endl;
return 0;
}

## Output:

The inversion sequence of the Sigma permutation:
0  0  2  1  3

## References:

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

### Returns

the inversion sequence of the given permutation

### Authors

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

Source code is available when you buy a Commercial licence.

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