I've completed the first function of the Problem set, where I've sorted every word in the dictionary into a trie, but I don't know if I was supposed to do that in the hash function, and something else in the load function. Can someone who's done this PSet please clarify for me? I don't find the instructions very helpful for answering this question.


1 Answer 1


the purpose of the hash function is to calculate a hash value for a given word and return that value. Nothing more.

The table[] array (or whatever you name it) is an array of pointers to the first element in each linked list. The hash value tells which table element will point to the correct linked list for a word. Load and check will call hash to get that number to use.

For example, say that the word "cat" has a hash value of 3. Load would call hash and pass it the word "cat". Hash would return "3" to load and then load would add a new node with the word "cat" to the linked list that table[3] points at.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

  • So in load, I never have to save every word from the dictionary into a hash table or a trie? If it's not for this, why does the comment over the function say, "Loads dictionary into memory, returning true if successful, else false"? I didn't think we were supposed to be checking words in load because of this comment :P. Commented May 15, 2023 at 13:33
  • I think you're still confused. Yes, ypu do have to load every word into a hash TABLE from the dictionary in the load function. Load does create a hash table and load words into it. It calls the hash function to get the hash value and then uses that value to determine where to put the word in the table. The hash function does NOT load the word into the hash table itself. Then, the check function later uses the hash function to determine the hash value of a word being checked to decide which part of the hash table to search for the word being checked.
    – Cliff B
    Commented May 15, 2023 at 23:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .