I knew the basics: array of buckets, linked list chaining, load factor.
Start by explaining the core data structure (array of buckets) and the put/get operations, then detail the collision resolution mechanism (linked list to red-black tree in Java 8+). Finally, highlight key changes across Java versions (e.g., treeification, hash function improvements) and discuss trade-offs like time complexity and resizing.
Pro tip: Mention that while HashMap is not thread-safe, ConcurrentHashMap uses similar principles with finer-grained locking; this shows awareness of concurrency trade-offs relevant to PayPal's high-throughput systems.
Explain that HashMap uses an array of Node objects (buckets) where each Node stores key, value, hash, and next pointer. The array size is a power of two for efficient indexing.
Describe how put computes hash, finds bucket index via (n-1) & hash, and handles collisions by traversing the linked list or tree. Get follows the same process to locate the key.
Explain that collisions are resolved via chaining: initially linked lists, but since Java 8, if a bucket's list exceeds 8 nodes and array size >= 64, it converts to a red-black tree for O(log n) search.
Discuss that when size exceeds load factor (default 0.75) * capacity, the array doubles and all entries are rehashed. This amortizes to O(1) but can cause temporary performance hits.
Highlight Java 7 vs 8 differences: Java 7 used linked lists only and had a weaker hash function; Java 8 introduced treeification, improved hash spreading, and changed resize logic to avoid infinite loops. Mention trade-offs like memory overhead vs. performance.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.
Start by briefly acknowledging separate chaining, then introduce open addressing (linear probing, quadratic probing, double hashing) and other strategies like cuckoo hashing and robin hood hashing. Compare them across time complexity, memory usage, and cache performance, emphasizing real-world trade-offs and when each is preferable.
Pro tip: Mention that open addressing with linear probing often outperforms chaining in practice due to cache locality, but requires careful load factor management to avoid clustering. Also, note that Java's HashMap uses chaining while Python's dict uses open addressing, showing you know real implementations.
Briefly explain that collision resolution handles cases where two keys hash to the same index, and separate chaining is one approach.
Introduce open addressing (linear probing, quadratic probing, double hashing), cuckoo hashing, and robin hood hashing as key alternatives.
Discuss average and worst-case time complexities for insert, search, and delete, noting that open addressing degrades with high load factors.
Compare memory overhead: chaining uses extra pointers and nodes, while open addressing stores entries directly in the table but may need larger table size.
Explain that open addressing has better cache locality due to contiguous memory access, while chaining suffers from pointer chasing and scattered memory.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.