You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>This implementation utilizes the observation that the elements that must be removed and reinserted
128
128
are exactly those elements that are not in the longest common subsequence.</p>
129
129
130
-
<p>Runtime: O(n^2), where n is the permutation length.</p>
130
+
<p>Runtime: O(n lg n), where n is the permutation length.</p>
131
131
132
132
<p>Reinsertion distance more generally was described in:<br>
133
133
V. A. Cicirello and R. Cernera, <ahref="https://www.cicirello.org/publications/cicirello2013flairs.html" target=_top>"Profiling the distance characteristics
134
134
of mutation operators for permutation-based genetic algorithms,"</a>
135
135
in Proceedings of the 26th FLAIRS Conference. AAAI Press, May 2013, pp. 46–51.</p>
136
136
137
-
<p>However, in that paper, it was computed using an adaptation of string Edit Distance.</p>
137
+
<p>However, in that paper, it was computed, in O(n^2) time, using an adaptation of string Edit Distance.</p>
138
138
139
139
<p>For description of computing it using the length of the longest common subsequence, see:<br>
140
140
V.A. Cicirello, <ahref="https://www.cicirello.org/publications/cicirello2016evc.html" target=_top>"The Permutation in a Haystack Problem
141
141
and the Calculus of Search Landscapes,"</a>
142
-
IEEE Transactions on Evolutionary Computation, 20(3):434-446, June 2016.</p></div>
142
+
IEEE Transactions on Evolutionary Computation, 20(3):434-446, June 2016.</p>
143
+
144
+
<p>However, that paper used an O(n^2) time algorithm for longest common subsequence. This class has been
145
+
updated to use a more efficient O(n lg n) algorithm for longest common subsequence. It is a version of
146
+
Hunt et al's algorithm
147
+
that has been optimized to assume permutations of the integers in [0, (n-1)] with unique elements.
148
+
The original algorithm of Hunt et al was for general strings that could contain duplicates and which could consist
149
+
of characters of any alphabet. In that more general case, O(n lg n) was the best case runtime. In our
150
+
special case, O(n lg n) is worst case runtime.</p>
151
+
152
+
<p>See the following for complete details of Hunt et al's algorithm for longest common subsequence:<br>
153
+
J.W. Hunt and T.G. Szymanski, "A fast algorithm for computing longest common subsequences,"
154
+
Communications of the ACM, 20(5):350-353, May, 1977.</p></div>
Copy file name to clipboardExpand all lines: src/org/cicirello/permutations/distance/ReinsertionDistance.java
+51-3Lines changed: 51 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -30,22 +30,34 @@
30
30
* <p>This implementation utilizes the observation that the elements that must be removed and reinserted
31
31
* are exactly those elements that are not in the longest common subsequence.</p>
32
32
*
33
-
* <p>Runtime: O(n^2), where n is the permutation length.</p>
33
+
* <p>Runtime: O(n lg n), where n is the permutation length.</p>
34
34
*
35
35
* <p>Reinsertion distance more generally was described in:<br>
36
36
* V. A. Cicirello and R. Cernera, <a href="https://www.cicirello.org/publications/cicirello2013flairs.html" target=_top>"Profiling the distance characteristics
37
37
* of mutation operators for permutation-based genetic algorithms,"</a>
38
38
* in Proceedings of the 26th FLAIRS Conference. AAAI Press, May 2013, pp. 46–51.</p>
39
39
*
40
-
* <p>However, in that paper, it was computed using an adaptation of string Edit Distance.</p>
40
+
* <p>However, in that paper, it was computed, in O(n^2) time, using an adaptation of string Edit Distance.</p>
41
41
*
42
42
* <p>For description of computing it using the length of the longest common subsequence, see:<br>
43
43
* V.A. Cicirello, <a href="https://www.cicirello.org/publications/cicirello2016evc.html" target=_top>"The Permutation in a Haystack Problem
44
44
* and the Calculus of Search Landscapes,"</a>
45
45
* IEEE Transactions on Evolutionary Computation, 20(3):434-446, June 2016.</p>
46
46
*
47
+
* <p>However, that paper used an O(n^2) time algorithm for longest common subsequence. This class has been
48
+
* updated to use a more efficient O(n lg n) algorithm for longest common subsequence. It is a version of
49
+
* Hunt et al's algorithm
50
+
* that has been optimized to assume permutations of the integers in [0, (n-1)] with unique elements.
51
+
* The original algorithm of Hunt et al was for general strings that could contain duplicates and which could consist
52
+
* of characters of any alphabet. In that more general case, O(n lg n) was the best case runtime. In our
53
+
* special case, O(n lg n) is worst case runtime.</p>
54
+
*
55
+
* <p>See the following for complete details of Hunt et al's algorithm for longest common subsequence:<br>
56
+
* J.W. Hunt and T.G. Szymanski, "A fast algorithm for computing longest common subsequences,"
57
+
* Communications of the ACM, 20(5):350-353, May, 1977.</p>
58
+
*
47
59
* @author <a href=https://www.cicirello.org/ target=_top>Vincent A. Cicirello</a>, <a href=https://www.cicirello.org/ target=_top>https://www.cicirello.org/</a>
48
-
* @version 2.18.8.2
60
+
* @version 2.18.8.17
49
61
* @since 1.0
50
62
*
51
63
*/
@@ -61,7 +73,43 @@ public int distance(Permutation p1, Permutation p2) {
0 commit comments