Question pretty much says it all. Specifically, I would like the Big-O of all the methods within a structure, aside from the usual. The docs say very little about this.
Addennum
For those who are voting to close, I am not interested in the basic add, remove, iterator, etc Those sources are fine for regularly used methods, but I am more interested in the algorithmic efficiency of the rest of the pile.
For example, what is the efficiency of开发者_StackOverflow中文版 TreeMap.keySet()
?
Java Collections Algorithm Efficiencies: Source
ArrayList
- get, set: O(1)
- add, remove: O(n)
- contains, indexOf: O(n)
HashMap
- get, put, remove, containsKey: O(1)
HashSet
- add, remove, contains: O(1)
LinkedHashSet
- add, remove, contains: O(1)
LinkedList
- get, set, add, remove (from either end): O(1)
- get, set, add, remove (from index): O(n)
- contains, indexOf: O(n)
PriorityQueue
- peek: O(1)
- add, remove: O(logn)
TreeMap
- remove, get, put, containsKey: O(logn)
TreeSet
- add, remove, contains: O(logn)
I would review the standard Big-O information about algorithms in Introduction_to_Algorithms.
I am not sure is there a spreadsheet or other list, but you can get this information in docs for every structure, for example TreeSet:
This implementation provides guaranteed log(n) time cost for the basic operations (add, remove and contains).
There really cannot be. Each JVM can have it's own runtime, with its own implementations. A few methods have specified O() characteristics, but the rest are whatever Sun, or Oracle, or IBM, or Apple, or Azul, does.
精彩评论