- All Implemented Interfaces:
public final class KendallTauDistance extends Object implements NormalizedPermutationDistanceMeasurerKendall Tau Distance:
Kendall Tau distance is sometimes also known as bubble sort distance, as it is the number of adjacent swaps necessary to transform one permutation into the other.
Another way of describing it is the number of pairs of elements whose order is inverted in one permutation relative to the other.
For example, consider p1 = [0, 1, 2, 3, 4] and p2 = [0, 3, 2, 1, 4]. The length is 5, so there are a total of 5*4/2 = 10 pairs of elements. 0 precedes all of 1, 2, 3, and 4 in both permutations. However, 1 precedes 2, 3, and 4 in p1, but only 4 in p2, so 2 adjacent swaps are needed for element 1. Elements 2 and 3 are in one order in p1, but switched in p2 relative to p1. So a total of 3 adjacent swaps are needed to transform p1 to p2. Kendall Tau distance is thus 3.
Kendall originally normalized the distance, but more recently many do not. Our implementation does not normalize.
Runtime: O(n lg n), where n is the permutation length. This runtime is achieved using a modified version of mergesort to count the inversions.
Kendall Tau distance originally described in:
M. G. Kendall, "A new measure of rank correlation," Biometrika, vol. 30, no. 1/2, pp. 81–93, June 1938.
Constructors Constructor Description
KendallTauDistance()Constructs the distance measurer as specified in the class documentation.
All Methods Instance Methods Concrete Methods Modifier and Type Method Description
distance(Permutation p1, Permutation p2)Measures the distance between two permutations.
max(int length)Computes the maximum possible distance between permutations of a specified length.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.cicirello.permutations.distance.NormalizedPermutationDistanceMeasurer
public int distance(Permutation p1, Permutation p2)Measures the distance between two permutations.
public int max(int length)Description copied from interface:
NormalizedPermutationDistanceMeasurerComputes the maximum possible distance between permutations of a specified length.