3 ms·
It seems really silly to compare the "search/insert/delete performance" of HashSet to HashMap to ArrayList to LinkedList, since the fundamental purpose of each
by brown9-2 10y ago
It seems really silly to compare the "search/insert/delete performance" of HashSet to HashMap to ArrayList to LinkedList, since the fundamental purpose of each class is different.
Not to mention that "search/insert/delete" are three separate operations with sometimes three different performance characteristics.
For instance it is incorrect to state that the insert/delete performance for LinkedList is O(n) - both are constant-time.
- swsieber 10y agoI'm not sure how LinkedList insert/delete performance isn't O(n) where n is the list length - care to shed some light? Are you assuming you have a node in the linked list? That might be constant, but the standard is to remove by index, and that's O(n).
- brown9-2 10y agoAh, I was assuming foolishly that we were talking about removing or inserting only at the head or the tail. All the more reason to be more detailed in a writeup than simply "Performance: O(n)" :)
- taco_emoji 10y agoInsertion and removal will always require traversal first since the LinkedList's node class is private.