I have forgotten

COST (GBP)
2.81
0.19
0

# Sign

Calculates the sign of the given permutation.
Controller: CodeCogs
Contents

C++

## Sign

 intsign( int n int* p )
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 $\inline&space;&space;1$ if the permutation is odd, and a value of $\inline&space;&space;-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

### Parameters

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

### Returns

the sign of the given permutation

### 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.