Computes the rank of the given permutation, as generated by Permutation Class 2.

View versions (1)

Interface

#include <codecogs/maths/combinatorics/permutations/rank.h>

using namespace Maths::Combinatorics::Permutations;

This function calculates at which call the Permutation Class 2 component would generate the given permutation. The value of the rank will be between 1 and n!. This function may be used with the Unrank component in order to give a method of recognizing certain permutations only by their rank number.

Example:

#include <codecogs/maths/combinatorics/permutations/rank.h>
#include <iostream>
int main()
{
  int sigma[3] = {2, 3, 1};
  std::cout << "The rank of the Sigma permutation is: ";
  std::cout << Maths::Combinatorics::Permutations::rank(3, sigma) << std::endl;
  return 0;
}

Output:

The rank of the Sigma permutation is: 5

References

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

Parameters

n
the size of the permutation
p
the actual permutation stored as an array

Returns

the rank of the given permutation, as generated by the <em> Permutation Class 2 </em> component
GPL Licence — free for non commercial use. See Licence details.