FUNCTION
Ulam_Distance
Computes the Ulam metric distance of two permutations.
You're viewing an older version of this page (#26). View the current version.
Interface
#include <codecogs/maths/combinatorics/permutations/ulam_distance.h>
using namespace Maths::Combinatorics::Permutations;
Consider two permutations of the same order
(1)
and
(2)
If we let be the length of the longest ascending subsequence of a permutation
, then the Ulam metric distance between
and
is given by:
(3)
where is the inverse of the
permutation.
This function calculates the value of based on the formula given above.
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/ulam_distance.h>
#include <iostream>
int main()
{
int sigma[5] = {1, 2, 3, 4, 5}, tau[5] = {5, 2, 1, 4, 3},
distance = Maths::Combinatorics::Permutations::ulam_distance(5, sigma, tau);
std::cout << "The Ulam metric distance of Sigma and Tau is: ";
std::cout << std::endl << distance << std::endl;
return 0;
}Output:
The Ulam metric distance of Sigma and Tau is:
3Parameters
n
the size of the permutations
a
the first permutation
b
the second permutation
Returns
the value of the Ulam metric distance between a and b
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.