Reputation: 275
I am trying to implement the median of medians algorithm in Java. I was wondering which of these two list implementations would cost less in terms of list traversal and comparison? Thanks!
Upvotes: 0
Views: 229
Reputation: 15250
An ArrayList
should be slightly more efficient because the algorithm needs some random access to the data structure that takes O(1) for the ArrayList
and O(n) for the LinkedList
.
LinkedList
is more efficient for remove operations (O(1) for LinkedList
and O(n) for ArrayList
), but this should not be the case in your algorithm.
Upvotes: 1