void insert(element_type key, HASH_TABLE H); position find(element_type key, HASH_TABLE H); position delete(element_type key, HASH_TABLE H);
Trees: O( ) or O( )
Hash Tables: O( ) but no find_min, find_max, sorted
Hash Function:
int hash(char *key, unsigned int H_SIZE) {
unsigned int hash_val = 0;
while (*key != '\0')
hash_val += *key++;
return(hash_val % H_SIZE);
}
hash("john",4) = 3 hash("mary",4) = 1 hash("dave",4) = 0
But hash("phil",4) = 1: collision
Solution 1: each table entry is beginning of a list (open hashing)
Solution 2: find an unused table entry (closed hashing)