Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

*Implementing HashMaps using Linked Lists as KVP\'s. The goal is to create a met

ID: 3739321 • Letter: #

Question

*Implementing HashMaps using Linked Lists as KVP's. The goal is to create a method that deletes a KVP if the Key is present within the map. The code within the delete method should not use methods already established in HashMaps such as remove() .

Using the following HashMapeK, V> class add: A method (void deletelk key) which deletes the key-value pair with the given key from the map if it is present. Note: Do not implement map resizing at this point. public class HashMapeK, Vs implements JRK, > private static final ?DE DEFAULT-NUM-BUCKETS 13; a Linked List of list of key-value pairs private Linked ListeKVPCK, V>21 buckets; private UEN; private int factor; public MutashMaalot M, iot factor] thisfacter- factor; this.bucket = new LinkedList[ M ]; for int i-ois bucket&Lenstbi; buckets[i] = new LinkedList

Explanation / Answer

//here is your function

public void delete(K key) {

if (key != null) {

for (int i = 0; i < bucket.length; i++) {

// override hashcode method

if (key.hashCode() == i) {// got the bucket where to search

List<KVP<K, V>> list = bucket[i];// get content of bucket to iterate over

for (int j = 0; j < list.size(); j++) {

KVP<K, V> kvp = list.get(j);

if (kvp.getKey().equals(key)) {// compare key to existing keys

// if key match

list.remove(j);

}

}

}

}

}

}