I have forgotten

• http://facebook.com/
• https://www.google.com/accounts/o8/id
• https://me.yahoo.com COST (GBP) 0.84 3.47 0

# Ulam Distance

Computes the Ulam metric distance of two permutations.
Controller: CodeCogs   ## Dependents C++

## Ulam Distance

 intulam_distance( int n int* a int* b )[inline]
Consider two permutations of the same order

and

If we let be the length of the longest ascending subsequence of a permutation , then the Ulam metric distance between and is given by:

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 = {1, 2, 3, 4, 5}, tau = {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:
3

### Parameters

 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

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