I am attempting to write a Java program that uses hashing for the following problem. Given a natural-language text, generate a list of distinct words with the number of occurrences of each word in the text. Insert appropriate counters in the program to compare the empirical efficiency of hashing with the corresponding theoretical results.
I understand the basic principle of hashing and hash tables, but I do not know how to implement it into a computer program. My textbook gives no examples, and my professor never went over any specific examples in my class.
I believe the program should first scan the text from a file, but I have no clue where to go after that.
Thank you for the help.
It sounds like you just need to research hashing. Hashing in general takes a range of values and maps them into some smaller range. So a simple hash function might be:
So my hash function takes number from the range (0 to 999) and maps them to (0 to 9). A good hashing function will distribute values evenly into the resulting range.
Your goal will be to map each word to some index into your hash table, which will not be as straight-forward as my example. You will have to do some research on hashing strings.
Good luck!