logo CodeStepByStep logo

hashMapAddMystery1

Language/Type: Java hashing implementing a collection
Related Links:

Write the final state of the hash map after the following key/value pairs are added and removed. Assume that it uses the standard "mod" hash function and uses linear probing for collision resolution. Write each pair in key=value format, or write X in any index in which an element is removed and not replaced by another element. Do not perform any resizing or rehashing.

HashMap<Integer, String> map = new HashMap<>();
map.put(8, "Q");
map.put(27, "J");
map.put(34, "T");
map.put(57, "R");
map.put(45, "Y");
map.put(74, "S");
map.put(27, "M");
map.put(95, "K");
map.remove(74);
map.put(76, "T");
map.remove(8);
map.remove(5);
map.put(14, "D");
element 0
element 1
element 2
element 3
element 4
element 5
element 6
element 7
element 8
element 9
element 10
element 11
element 12
element 13
element 14
element 15
element 16
element 17
element 18
element 19

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.