Question: Can you please explain how we get the answer (d) in this question? I dont understand how they got the answer. Refer to the implementation
Can you please explain how we get the answer (d) in this question?
I dont understand how they got the answer.
Refer to the implementation provided below to answer the question.
A HashTable using Linear Probing has: size an int buckets: an array of Entries (not of lists of Entries!) hash: a hash function for the Key type An Entry is a single (key: value) pair void set (key, value): if loadFactor > 0.67: expandCapacity() hashed hash(key) index hashed % array length while this.buckets[index]null bthis.buckets[index if b.key.equals(key) b.value value return index += 1 // key not in table, add it at first index containing null this.buckets[index](key: value) Value get (key) hashed- hash(key) index hashed % this.buckets.length while this.buckets[index]!null: bthis.buckets[index] if b.key.equals(key) return b.value index += 1 // haven't found the key return null/throw exception void expandCapacity(): newEntries new Entrylthis.buckets.length 2]: oldEntries this.buckets this.buckets newEntries this.size0 for each entry (kv in oldEntries: this.set(k, v) int hash(char key) return (int) key; 5. Which of the following sequences of insertions would cause the most collisions for a hash table with four buckets and assuming expandCapacity is not called during the adds? add(A', 56); add(B', 5); add('C, 65); add D', 2); add('L', 160); O add(M, 58); add'Q, 14); add(U, 20) add(W, 37); add'N', 7); add(R, 24); add(V, 90); add(Z, 100); add('Z, 91); add('R', 604); add(P, 9); add(L', 5)