From e4d87b4b075bbf1057e6d22f381622a84f8a19eb Mon Sep 17 00:00:00 2001
From: Luke Butters 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).
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.