FUNCTION
Sign
Calculates the sign of the given permutation.
You're viewing an older version of this page (#5343). View the current version.
Interface
#include <codecogs/maths/combinatorics/permutations/sign.h>
using namespace Maths::Combinatorics::Permutations;
A permutation can always be replaced by a sequence of pairwise transpositions. A given permutation can be represented by many different such transposition sequences, but the number of such transpositions will always be odd or always be even. If the number of transpositions is even or odd, the permutation is said to be even or odd. This function returns a corresponding value of $-1$ if the permutation is odd, and a value of $1$ if it is even.
Example:
#include <codecogs/maths/combinatorics/permutations/sign.h>
#include <iostream>
int main()
{
int alpha[5] = {4, 3, 5, 1, 2};
std::cout << "The sign of the Alpha permutation is: ";
std::cout << Maths::Combinatorics::Permutations::sign(5, alpha) << std::endl;
return 0;
}
Output:
The sign of the Alpha permutation is: -1
References
SUBSET, a C++ library of combinatorial routines, http://www.csit.fsu.edu/~burkardt/cpp_src/subset/subset.html