FUNCTION
Derangement_Check
Verifies if a given permutation is a derangement.
Interface
#include <codecogs/maths/combinatorics/permutations/derangement_check.h>
using namespace Maths::Combinatorics::Permutations;
This function checks whether a given permutation, given as an array of numbers in the range , is a derangement. A derangement of the integers 1 through n is a permutation of the integers such that the first value is not 1, the second is not 2, and so on. In more formal terms, the following condition stands:
(1)
where is the given permutation.
Example:
#include <codecogs/maths/combinatorics/permutations/derangement_check.h>
#include <iostream>
int main()
{
int x[4] = {4, 3, 2, 1}, y[5] = {1, 3, 2, 5, 4};
std::cout << Maths::Combinatorics::Permutations::derangement_check(4, x) << std::endl;
std::cout << Maths::Combinatorics::Permutations::derangement_check(4, y) << std::endl;
return 0;
}
Output:
1
0
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
a
the actual permutation given as an array
Returns
true, if the permutation is a derangement, false otherwise
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.