首頁 > Java > java教程 > 文章的標題應該是:What are the Big-O Time Complexities of Java Collection Implements?

文章的標題應該是:What are the Big-O Time Complexities of Java Collection Implements?

Linda Hamilton
發布: 2024-10-28 02:33:31
原創
842 人瀏覽過

The title of the article should be: What are the Big-O Time Complexities of Java Collection Implementations?

Java 集合框架實作:大O 總結

在教授「Java 速成課程」時,了解以下內容至關重要與各種集合實現相關的Big-O 時間複雜度。雖然觀眾可能熟悉 Big-O 表示法,但他們不太可能知道特定集合上不同操作的特定複雜性。

幸運的是,《Java 泛型和集合》一書提供了有關這些複雜性的寶貴見解。本文總結了書中的信息,為每種類型的集合提供了詳細的表格:列表、集合、映射和隊列。

列表實作:

Operation ArrayList LinkedList CopyOnWriteArrayList
get O(1) O(n) O(1)
add O(1) O(1) O(n)
contains O(n) O(n) O(n)
next O(1) O(1) O(1)
remove(0) O(n) O(1) O(n)
iterator.remove O(n) O(1) O(n)

集合實作:

Operation HashSet LinkedHashSet CopyOnWriteArraySet EnumSet TreeSet ConcurrentSkipListSet
add O(1) O(1) O(n) O(1) O(log n) O(log n)
contains O(1) O(1) O(n) O(1) O(log n) O(log n)
next O(h/n) O(1) O(1) O(1) O(log n) O(1)
Notes h is the table capacity

實作地圖:

>
Operation HashMap LinkedHashMap IdentityHashMap EnumMap TreeMap ConcurrentHashMap ConcurrentSkipListMap
get O(1) O(1) O(1) O(1) O(log n) O(1) O(log n)
containsKey O(1) O(1) O(1) O(1) O(log n) O(1) O(log n)
next O(h/n) O(1) O(h/n) O(1) O(log n) O(h/n) O(1)
Notes h is the table capacity

隊列實作:

Operation PriorityQueue ConcurrentLinkedQueue ArrayBlockingQueue LinkedBlockingQueue PriorityBlockingQueue DelayQueue LinkedList ArrayDeque LinkedBlockingDeque
offer O(log n) O(1) O(1) O(1) O(log n) O(log n) O(1) O(1) O(1)
peek O(1) O(1) O(1) O(1) O(1) O(1) O(1) O(1) O(1)
poll O(log n) O(1) O(1) O(1) O(log n) O(log n) O(1) O(1) O(1)
size O(1) O(n) O(1) O(1) O(1) O(1) O(1) O(1) O(1)

以上是文章的標題應該是:What are the Big-O Time Complexities of Java Collection Implements?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
作者最新文章
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板