Big-O Notation untuk Pelaksanaan Rangka Kerja Java Collections
Dalam menjangkakan kursus ranap Java yang akan datang, adalah penting untuk menyediakan ringkasan ringkasan kerumitan masa pelbagai operasi pada pelaksanaan koleksi yang berbeza.
Senarai Pelaksanaan
Implementation | get | add | contains | next | remove(0) | iterator.remove |
---|---|---|---|---|---|---|
ArrayList | O(1) | O(1) | O(n) | O(1) | O(n) | O(n) |
LinkedList | O(n) | O(1) | O(n) | O(1) | O(1) | O(1) |
CopyOnWrite-ArrayList | O(1) | O(n) | O(n) | O(1) | O(n) | O(n) |
Tetapkan Pelaksanaan
Implementation | add | contains | next | Notes |
---|---|---|---|---|
HashSet | O(1) | O(1) | O(h/n) | h is the table capacity |
LinkedHashSet | O(1) | O(1) | O(1) | - |
CopyOnWriteArraySet | O(n) | O(n) | O(1) | - |
EnumSet | O(1) | O(1) | O(1) | - |
TreeSet | O(log n) | O(log n) | O(log n) | - |
ConcurrentSkipListSet | O(log n) | O(log n) | O(1) | - |
Pelaksanaan Peta
Implementation | get | containsKey | next | Notes |
---|---|---|---|---|
HashMap | O(1) | O(1) | O(h/n) | h is the table capacity |
LinkedHashMap | O(1) | O(1) | O(1) | - |
IdentityHashMap | O(1) | O(1) | O(h/n) | h is the table capacity |
EnumMap | O(1) | O(1) | O(1) | - |
TreeMap | O(log n) | O(log n) | O(log n) | - |
ConcurrentHashMap | O(1) | O(1) | O(h/n) | h is the table capacity |
ConcurrentSkipListMap | O(log n) | O(log n) | O(1) | - |
Pelaksanaan Barisan
Implementation | offer | peek | poll | size |
---|---|---|---|---|
PriorityQueue | O(log n) | O(1) | O(log n) | O(1) |
ConcurrentLinkedQueue | O(1) | O(1) | O(1) | O(n) |
ArrayBlockingQueue | O(1) | O(1) | O(1) | O(1) |
LinkedBlockingQueue | O(1) | O(1) | O(1) | O(1) |
PriorityBlockingQueue | O(log n) | O(1) | O(log n) | O(1) |
DelayQueue | O(log n) | O(1) | O(log n) | O(1) |
LinkedList | O(1) | O(1) | O(1) | O(1) |
ArrayDeque | O(1) | O(1) | O(1) | O(1) |
LinkedBlockingDeque | O(1) | O(1) | O(1) | O(1) |
Sumber Tambahan
Untuk penerokaan lanjut, pertimbangkan sumber berharga ini:
Atas ialah kandungan terperinci Apakah Kerumitan Masa Big-O bagi Operasi Rangka Kerja Koleksi Java Berbeza?. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!