




















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





















(key, element) Pairs have different keys.
get(theKey) put(theKey, theElement) remove(theKey)
put() implemented as update when there is already a pair with the given key. remove() followed by put().
a = (aKey, aElement), b = (bKey, bElement), etc.
a b c d e
O(size) time
O(size) time to verify duplicate, O(1) to add at right end.
O(size) time.
O(size) time
O(size) time to verify duplicate, O(1) to add at left end.
O(size) time.
a b c d e
firstNode null
O(size) time
O(size) time to verify duplicate, O(1) to put at proper place.
A B C D E
firstNode null
O(size).
O(size).
[0] [1] [2] [3] [4] [5] [6] [7]
(3,d) (22,a) (33,c) (73,e) (85,f)
[0] [1] [2] [3] [4] [5] [6] [7]
(3,d) (22,a) (33,c) (73,e) (85,f)
Convert key into an integer in case the key is not an integer.
f(k) is an integer in the range [0, b-1], where b is the number of buckets in the table.
public static int integer(String s)
{
int length = s.length(); // number of characters in s int answer = 0; if (length % 2 == 1) {// length is odd answer = s.charAt(length - 1); length--; }
// length is now even for (int i = 0; i < length; i += 2) {// do two characters at a time answer += s.charAt(i); answer += ((int) s.charAt(i + 1)) << 16; } return (answer < 0)? -answer : answer;
}