diff --git a/src/main/java/org/ahocorasick/util/ListElementRemoval.java b/src/main/java/org/ahocorasick/util/ListElementRemoval.java index 96ec96c..ac64806 100644 --- a/src/main/java/org/ahocorasick/util/ListElementRemoval.java +++ b/src/main/java/org/ahocorasick/util/ListElementRemoval.java @@ -9,16 +9,15 @@ import java.util.List; *
Removing elements from an ArrayList in a naive way can lead to O(n^3) * running time. If the algorithm first creates a list of all the elements * to remove, then we for each element in this list (assume n elements) we look - * for in element in the list (against n elements) and when found we need to remove - * the element and move the elements to the right one to the left the size of this - * operation is at worst n hence O(n^3).
+ * for the element in the original list (against n elements) and when found we need + * to remove the element and move the elements to the right (of the removed element) + * to the left by one, the size of this operation is at worst n hence O(n^3). * - *This basically avoids that by making a new list and copying over only elements - * we want to keep, we then clear the given list and all of the elements this gives us - * (for ArrayList) O(n) running time.
+ *This instead makes a new list and copies over only elements we want to keep, + * we then clear the original list and then add all of the elements to the original + * list. This gives us (for ArrayList) a running time of O(n).
* - *The performance of this has not been thoroughly tested for linked list but - * it probably is not too bad.
+ *The performance of this has not been thoroughly tested for linked list.
* *This can be completely removed in java 8 as the List#removeIf() method can be used instead * as this already is optimised for each list implementation.