FUNCTION
Inversion_Sequence
Computes the inversion sequence of a permutation.
You're viewing an older version of this page (#5340). View the current version.
Interface
#include <codecogs/maths/combinatorics/permutations/inversion_sequence.h>
using namespace Maths::Combinatorics::Permutations;
For a given permutation
$$\sigma = \left( \begin{array}{cccc} 1 & 2 & \ldots & n \cr
\sigma(1) & \sigma(2) & \ldots & \sigma(n) \end{array} \right)$$
(1)
the inversion sequence $( \alpha )$ is defined as
$$\alpha(i) = \mathrm{card} \{ j < i | \sigma(i) < \sigma(j) \},
\quad \forall i = \overline{1, n}$$
(2)
with $\alpha(1) = 0$.
This function calculates the inversion sequence of a permutation based on the above formula and returns its value as a C++ vector object.
Parameters
n
the size of the permutation
p
the actual permutation given as an array
Returns
the inversion sequence of the given permutation
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
This function's source code is only visible to registered users — documentation and the calculator above are free to use either way. Sign in to see it.