c++ - Difference between permutations -
this question has answer here:
is there way compute quantitatively distance between 2 permutations?
suppose have following 2 sequences of elements:
a = {0, 1, 2, 3} b = {0, 3, 2, 1}
i permutation b
differs a
because:
- i require 1 swap operation in order transform
b
a
- there 2 elements within
b
have index different same elements ina
are there other ways compare , describe difference between two?
the main goal define algorithm able approach second permutation b
first 1 a
, such if steps of procedure applied outcome permutation a
itself. in order to think should best define first sensible procedure describes how b
differs a
.
is there known algorithm allows approach on permutation another?
there few different ways define difference between 2 sequences. name few:
hamming distance: number of positions @ elements differ.
hamming(a, b) b[1] different a[1] , b[3] different a[3] => 2
levenshtein distance: minimum number of modifications necessary 1 sequence another.
levenshtein(a, b) replace b[1] a[1] , replace b[3] a[3] => 2
damerau–levenshtein distance: extension of former takes account transpositions.
damerau_levenshtein(a, b) transpose b[3] b[1] => 1
based upon given example, interested in tracking transpositions , therefore damerau–levenshtein distance best bet.
Comments
Post a Comment