Java Lab 5, Activity 1. Hashing

1. Draw the 11-entry hash table that results from using the hash function, h(i) = (3i+5) mod 11, to hash the keys 12, 44, 13, 88, 23, 94, 11, 39, 20, 16, and 5, assuming collisions are handled by chaining.

 

2. Redo P1 assuming collisions are handled by linear probing.

 

3. Redo P1 assuming collisions are handled by double hashing using the secondary hash function d(k) = 7− (k mod 7).

 

4. Hash code is used to “encode” general keys into integers. One approach of creating a hash code is to use Java's hashCode() method. The hashCode() method is implemented in the Object class and therefore each class in Java inherits it. The hash code provides a numeric representation of an object (this is somewhat similar to the toString method that gives a text representation of an object). 

a. Write a program to show the hash code of the following.

    Integer 2018, 

    String “2018”, 

    StringBuffer “2018”, 

    ArrayList with first element is Integer 2018.

b. Verify that different objects might have the same hashcode. For example, show the hashcode for the strings “Aa” and “BB”.

 

Need a custom answer at your budget?

This assignment has been answered 3 times in private sessions.

© 2020 Codify Tutor. All rights reserved