Programming Problems in Java by Green Bradley & Wong James

Programming Problems in Java by Green Bradley & Wong James

Author:Green, Bradley & Wong, James
Language: eng
Format: epub
Published: 2015-05-18T16:00:00+00:00


* * *

Listing 6.1: A Simple Hash Function

int hash_simple(String str) {

if (str.isEmpty()) {

return 0;

}

return str.charAt(0) - 'a';

}

* * *

This function is deterministic and extremely efficient, its range is limited to only 26 values and hence many strings will hash to the same value. Further, the corpus of English words is not uniformly distributed across these 26 values. An examination of the words in the Gutenberg library shows that 17% of the words start with t, nearly 12% of words start with the letter a but only 0.05% of words start with z.

To overcome these two problems, we add complexity to the calculation of the hash value.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.