Glossary#
| Term | Plain meaning | Chapter |
|---|---|---|
| Collections Framework | Java's standard data-structure library | 1 |
| List / Set / Queue / Deque / Map | sequence / unique items / take from front / both ends / key→value | 1 |
| ArrayList / capacity | growable array / current internal array size | 2 |
| LinkedList / node | doubly linked list / one element + prev/next links | 2 |
| immutable vs fixed-size | List.of (no changes) vs Arrays.asList (set OK, no add/remove) | 2 |
| Iterator / fail-fast | walker with hasNext/next/remove / throws on outside modification | 3 |
| ConcurrentModificationException | collection changed during iteration | 3 |
| HashMap / bucket / table | hash-based map / one slot of the array / the array | 4 |
| hash spreading | h ^ (h >>> 16) before choosing a bucket | 4 |
| collision / chaining | two keys, same bucket / a list per bucket | 4 |
| treeification | bucket list → red-black tree at 8 entries | 4 |
| load factor / resize / rehash | 0.75 fullness threshold / double the table / re-place entries | 4 |
| HashSet | a HashMap with only keys | 5 |
| LinkedHashMap / access order | insertion-ordered map / reads move entries to the end | 5 |
| LRU cache | evicts the least recently used entry | 5 |
| TreeMap / TreeSet / red-black tree | sorted map / sorted set / self-balancing BST inside | 6 |
| floor / ceiling / higher / lower | ≤ / ≥ / > / < nearest key | 6 |
| Comparable / Comparator | natural order (compareTo) / external rule (compare) | 7 |
| stable sort / TimSort | equal elements keep order / Java's object sort | 7 |
| FIFO / LIFO | queue order / stack order | 8 |
| ArrayDeque / circular array | the stack+queue class / wrap-around array inside | 8 |
| offer/poll/peek vs add/remove/element | return null/false vs throw | 8 |
| PriorityQueue / binary heap / min-heap | smallest-first queue / array-based tree / parent ≤ children | 9 |
| sift up / sift down / heapify | fix after offer / after poll / build from a collection in O(n) | 9 |
| top-K pattern | size-k min-heap for the k largest | 9 |
| unmodifiable view vs immutable copy | read-only window vs true snapshot | 10 |
| EnumMap / BitSet / WeakHashMap | enum keys / compact int set / GC-aware keys | 10 |
Cheat Sheet#
Declarations you'll type daily
List<Integer> list = new ArrayList<>();
Map<String, Integer> cnt = new HashMap<>();
Set<Integer> seen = new HashSet<>();
Map<Integer, List<Integer>> graph = new HashMap<>();
Deque<Integer> stack = new ArrayDeque<>();
Deque<int[]> queue = new ArrayDeque<>();
PriorityQueue<Integer> minH = new PriorityQueue<>();
PriorityQueue<Integer> maxH = new PriorityQueue<>(Comparator.reverseOrder());
PriorityQueue<int[]> pq = new PriorityQueue<>((a, b) -> Integer.compare(a[0], b[0]));
TreeMap<Integer, Integer> tm = new TreeMap<>();
Set<List<Integer>> uniqueTriples = new HashSet<>();Idioms
cnt.merge(k, 1, Integer::sum); cnt.getOrDefault(k, 0)
graph.computeIfAbsent(u, x -> new ArrayList<>()).add(v);
for (var e : map.entrySet()) { e.getKey(); e.getValue(); }
if (!seen.add(x)) { /* duplicate */ }
list.removeIf(x -> x < 0); list.sort(Comparator.comparingInt(...).reversed().thenComparing(...));
Arrays.sort(arr2d, (a, b) -> Integer.compare(a[0], b[0])); // never a[0] - b[0]
stack.push(x); stack.pop(); stack.peek(); queue.offer(x); queue.poll(); queue.peek();
tm.floorKey(k); tm.ceilingKey(k); tm.firstKey(); tm.pollFirstEntry(); tm.headMap(k); tm.tailMap(k);
top-K largest: min-heap, offer, if (size > k) pollCosts
ArrayList get/set O(1) · add end amortized O(1) · add/remove front O(n) · contains O(n)
HashMap/Set O(1) avg (tree bucket worst O(log n)) · resize at size > 0.75 × capacity, doubles
TreeMap/Set O(log n) all · floor/ceiling O(log n)
ArrayDeque O(1) both ends
PriorityQ peek O(1) · offer/poll O(log n) · remove(obj)/contains O(n) · heapify O(n)
heap index: parent (i−1)/2 · children 2i+1, 2i+2Try This Yourself#
Build a tiny HashMap. Write
MyHashMap<K, V>with an array of 16 buckets (each a linked list of nodes),put,get, and doubling at 0.75 load. Test it with 1,000 keys againstjava.util.HashMap. Then make a key class withhashCode()returning 42 always and watch yourgetslow down.Build a tiny heap. Write
MinHeapon anint[]withoffer(sift up) andpoll(sift down). Check it againstPriorityQueueon random input.LRU both ways. Implement an LRU cache with
LinkedHashMap(Ch 5), then again with aHashMapplus your own doubly linked list — LeetCode 146.Pick the collection. For each, name the collection and the complexity: (a) the first non-repeating character in a string; (b) all students with scores between 150 and 180; (c) process tasks in the order received; (d) the running median of a stream of numbers (hint: two heaps).