I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
get GPL
COST (GBP)
this unit 0.84
sub units 3.47
+
0

Ulam Distance

Computes the Ulam metric distance of two permutations.
Controller: CodeCogs

Dependents

Info

Interface

C++

Ulam Distance

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

and

If we let \inline  L(\alpha) be the length of the longest ascending subsequence of a permutation \inline  \alpha, then the Ulam metric distance between \inline  \sigma and \inline  \tau is given by:

where \inline  \overline{\tau} is the inverse of the \inline  \tau permutation.

This function calculates the value of \inline  U 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:
3

Parameters

nthe size of the permutations
athe first permutation
bthe 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.