Reports the unused items in a partial permutation.

You're viewing an older version of this page (#5346). View the current version.

View versions (2)

Interface

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

using namespace Maths::Combinatorics::Permutations;

Given a whole positive number $n$, representing the size of the original permutation, a partial permutation $\tau$ is one of size $m < n$ that satisfies the following conditions:

$$\tau = \left( \begin{array}{cccc} 1 & 2 & \ldots & m \cr \tau(1) & \tau(2) & \ldots & \tau(m) \end{array} \right) \qquad \tau(i) \in \{1, 2, \ldots, n \}$$
(1)

with

$$\tau(i) \neq \tau(j), \quad \forall i, j \in \{ 1, 2, \ldots, m \}, \quad i \neq j$$
(2)

This function performs a linear search to find the unused items in the given partial permutation and returns them as a C++ vector object.

References

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

Example 1

#include <codecogs/maths/combinatorics/permutations/unused_items.h>
#include <iostream>
int main()
{
  int alpha[5] = {1, 5, 2, 7, 9}, n = 10;
  std::vector<int> result = Maths::Combinatorics::Permutations::unused_items(n, 5, alpha);
  std::cout << "The unused values in the partial permutation Alpha are:";
  std::cout << std::endl;
  for (int i = 0; i < result.size(); i++)
    std::cout << result[i] << " ";
  std::cout << std::endl;
  return 0;
}

Output:

The unused values in the partial permutation Alpha are:
3 4 6 8 10

Parameters

n
the size of the original permutation
npart
the size m of the partial permutation
part
the partial permutation, as an array of npart integers in $\{1, \ldots, n\}$

Returns

the unused items in the given partial permutation
GPL Licence — free for non commercial use. See Licence details.