Question: ( 1 0 Points ) Read a file and hash the words: Read a text file ( there are several named in the table below

(10 Points) Read a file and hash the words:
Read a text file (there are several named in the table below and posted on
Canvas) and hash the words using the suggested hash function from Levitin,
page 269:
h 0; for i 0 to s 1 do h (h C + ord(ci)) mod m,
where:
h is the computed hash value,
s is the length of the word being hashed,
ci is the ith character of the word,
ord(c) is the numerical value of character c in the alphabet in use,
C is a constant larger than every ord(ci), and
m is the modulus defining the size of our hash table.
We will take ord(c) to be the ASCII value of the characters in each word. Thus,
ord(c) in {39,45,65,66,...,90,97,98,...122} for c in {,-, A, B,..., Z, a, b,..., z},
respectively. All other characters are discarded; we define words as unbroken
sequences (strings!) of consecutive alphabetic characters, both upper and lower
case, plus apostrophes and hyphens1, in the lines read for the file. (Java uses
Unicode, but ASCII is still under there somewhereyou just need to dig it out.)
Well start simply with TheRavenB24.txt text file, and we will take C =123
and m =1000, even though its not prime. These represent parameters that
can be changed to alter the shape and composition of our resulting hash table.
Well increase the size of our table when we use the appended files.
You are free to experiment with changing these parameters on your own, of
course!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!