Cuckoo Hash Table public class CuckooHash { insert str -> void // O(N) remove str -> void // O(1) lookup str -> bool // O(1) init int -> void // 2 hash tables : default/easy // 1 single large array + 2 hash functions : implement // n hash functions, m arrays - 95% 3 hash tables/functions // randomize or serialize hash function usage // lambda : load function = no of elements / tablesize int tablesize = 101; array1 : string array of size tablesize array2 : string array of size tablesize // 2 hash functions s.t. h1(A) = h1(B) and h2(A) = h2(B) => A = B int hash1 (string s) { Caden & Dacen, Nasus & Susan } int hash2 (string s) { } Violates independence if same first initial and same letters in different order string insert_help(string s, int table) { hash = hash[table](s); ret_val = NULL; if (array[table][hash] == NULL) ret_val = array[table][hash]; } array[table][hash] = s; return ret_val; } void insert(string s) { iter = 0; while (ret_val != NULL) { iter = iter + 1; ret_val = insert_help(s, iter % 2); if (iter > 5) { rehash(); } } if lambda > desired_lambda, then rehash(); } bool lookup(string s) { h1 = hash1(s); h2 = hash2(s); return array1[h1] == s OR array2[h2] == s; } void remove(string s) { h1 = hash1(s); h2 = hash2(s); if (array1[h1] == s) { array1[h1] = NULL; } if (array2[h2] == s) { array2[h2] = NULL; } return; } void rehash() { temp1 = array1; temp2 = array2; old_tab = tablesize; tablesize *= 2; tablesize = nextprime(tablesize); array1 = new_array(tablesize); array2 = new_array(tablesize); // Assuming null-initialized array for (int i = 0; i < old_tab; i++) { if (temp1[i] != NULL) { insert(temp1[i]); } if (temp2[i] != NULL) { insert(temp2[i]); } } } }