## Class LeeDistance

• All Implemented Interfaces:
`NormalizedPermutationDistanceMeasurer`, `NormalizedPermutationDistanceMeasurerDouble`, `PermutationDistanceMeasurer`, `PermutationDistanceMeasurerDouble`

```public final class LeeDistance
extends Object
implements NormalizedPermutationDistanceMeasurer```
Lee Distance:

Lee Distance is closely related to deviation distance. However, Lee Distance considers the permutation to be a cyclic structure when computing positional deviations. That is, an element's deviation between permutations is the minimum of its deviation to the right or to the left (wrapping around ends cyclicly).

Consider p1 = [0, 1, 2, 3, 4, 5] and p2 = [5, 1, 0, 2, 3, 4]. Element 0 is 2 positions displaced (as in deviation distance). Elements 2, 3, and 4 are a 1 position displaced (as in deviation distance). Element 1 is stationary. Element 5 is 1 position displaced (for Lee Distance) whereas for Deviation Distance it would be 5 positions displaced. For Lee distance, the displacement is the minimum of how far it is displaced in either of the two directions. In this case element 5 is at the right most end in p1 and left most end of p2, which as a cyclic structure are adjacent positions.

Runtime: O(n), where n is the permutation length.

Described in:
C. Lee, "Some properties of nonbinary error-correcting codes," in IRE Transactions on Information Theory, vol. 4, no. 2, pp. 77-82, June 1958.

• ### Constructor Summary

Constructors
Constructor Description
`LeeDistance()`
Constructs the distance measurer as specified in the class documentation.
• ### Method Summary

All Methods
Modifier and Type Method Description
`int` ```distance​(Permutation p1, Permutation p2)```
Measures the distance between two permutations.
`int` `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

`maxf, normalizedDistance`
• ### Methods inherited from interface org.cicirello.permutations.distance.PermutationDistanceMeasurer

`distancef`
• ### Constructor Detail

• #### LeeDistance

`public LeeDistance()`
Constructs the distance measurer as specified in the class documentation.
• ### Method Detail

• #### distance

```public int distance​(Permutation p1,
Permutation p2)```
Measures the distance between two permutations.
Specified by:
`distance` in interface `PermutationDistanceMeasurer`
Parameters:
`p1` - first permutation
`p2` - second permutation
Returns:
distance between p1 and p2
Throws:
`IllegalArgumentException` - if p1.length() is not equal to p2.length().
• #### max

`public int max​(int length)`
Description copied from interface: `NormalizedPermutationDistanceMeasurer`
Computes the maximum possible distance between permutations of a specified length.
Specified by:
`max` in interface `NormalizedPermutationDistanceMeasurer`
Parameters:
`length` - Permutation length.
Returns:
the maximum distance between a pair of permutations of the specified length.