As of May 31, 2023, we have updated our Code of Conduct.

Questions tagged [hash-table]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
2 votes
1 answer
2k views

How to know how many buckets for hash table - Speller PSET5

I am implementing the hash table for load at the moment, but I don't know how I should figure out how many buckets I should be using. Is there a 'rule' for this when creating hash functions, or is it ...
Davis's user avatar
  • 144
0 votes
1 answer
691 views

Segmentation fault occurs if I delete an unused global variable in Pset5

It looks I have broken C while working on Pset5, I mean, I don't understand a bit why this happens. First, I completed the problem with the simplest of hash functions which just processes the first ...
devwanderer's user avatar
0 votes
1 answer
340 views

Too many misspelled words - speller.c PSET-5

I'm using a hash table to implement the spell checker for speller.c with a hash function I found on reddit but it prints out way too many misspelled words and I have no idea why. Any help would be ...
user34304's user avatar
  • 141
0 votes
1 answer
410 views

How can I optimize load in pset5

I'm trying to optimize my load function (after using gprof to profile speller), as it takes 99.6% time of my program. How can I do it? Here is dictionary.c: /* This function opens a dictionary file ...
Cstudent's user avatar
1 vote
1 answer
676 views

pset5, load function. Initializing elements in hashtable to null

This is my load function from dictionary.c. I'm trying to create a hashtable of linked lists with separate chaining. There are 26 elements corresponding to each letter in the alphabet. My questions ...
tadm123's user avatar
  • 215
0 votes
2 answers
340 views

Pset5 - Problem with hash table load(), malloc, and segmentation-fault

I am having problem with the load function. When I run: valgrind --leak-check=full ./speller texts/austinpowers.txt it gives me the following report (I am using the small dictionary to test my code) ...
Levblanc 's user avatar
0 votes
1 answer
35 views

Pset5: I get a seg fault when looking for a word that is not in the dictionary

I get a seg fault when running the code below. I ran GDB and what I can tell is that it works well when the word I look for is in the dictionary (e.g. this), but that it does not work when the word is ...
CB Nuji's user avatar
  • 21
0 votes
1 answer
81 views

Pset5 segmentation fault in load function using hash table

I always get a seg fault in this specific function. I've checked it with GDB, and the line causing seg fault is hashtable[index]->next = tmp_node. bool load(const char* dictionary) { FILE* dict = ...
Lúcio Cardoso's user avatar
0 votes
1 answer
67 views

Pset5 - dictionaries.c : My check output is very unrelated and confusing

i believe my load function is already working properly, i use fgets, and i have deleted the newline character in each word. but when it comes to check (i think..) it gives me unrelated output. this ...
Patrick Benz Imanuel's user avatar
2 votes
2 answers
131 views

how effective would it have been to use an array for the dictionary?

I just completed pset5 using a trie, but I'm curious about other methods. How effective would it have been to load the dictionary into an array and then use a binary search function to locate words ...
736f5f6163636f756e74's user avatar
0 votes
1 answer
140 views

Unload-function seems to trigger segfault

I'm having some difficulties with pset5 - Mispellings. My program, which uses a hash-table, seemed to work fine until I implemented the unload-function. I used the function shown in the walkthrough by ...
hoekschop's user avatar
0 votes
3 answers
313 views

Declaring struct node and node array globally (hashtable implementation)

When coding load (using the hashtable method), I declared the structure for a node and an array of nodes within the function. However, this--of course--means I can't use these things in the check ...
Andrea Perry's user avatar
0 votes
2 answers
108 views

My hash table works and has good running time but fails one check - :( handles max length (45-char) words

My hash table works and has good running time but fails for one check (rest all checks pass) - :( handles max length (45-char) words AFAIK pneumonoultramicroscopicsilicovolcanoconiosis is the longest ...
hagrawal7777's user avatar
0 votes
1 answer
87 views

pset5 Load: Am I on the right track? Getting errors for pointer/integer confusion

As the title suggests I having a bit of trouble with my if and else down at the bottom of my code. Errors are arising that say incompatible pointer to integer conversion. I am a bit confused as to ...
peachykeen's user avatar
0 votes
1 answer
229 views

pset5 speller: loads one more word

Whenever I load words from the dictionary and check the number of words in the dictionary, it seems to load one more than there actually is. For example, if I load the SMALL dictionary, number of ...
James C's user avatar
0 votes
1 answer
238 views

What's wrong with my load function? for cs50, pset5. Im sure all other functions are correct

I tried to figure it out using gdb, failed miserably. bool load(const char* dictionary){ FILE* fp = fopen(DICTIONARY, "r" ); new_node = malloc(sizeof(struct node)); while(!feof(fp)) { ...
AnirudhKonduru's user avatar
0 votes
1 answer
218 views

PSET5 What LOAD really supposed to do?

I'm starting Problem Set nb 5 and just need a couple more specifications to begin my implementation of LOAD. Is it good to assume that a lexicographically sorted dictionary corresponds to a ...
CharlesD89's user avatar
1 vote
1 answer
638 views

pset5 speller.c with hashtable errors and seg fault

this is my code so far for pset5. I would appreciate giving me hints about my erros. I also get a segmentation fault. thanks. when I implemented load and check only, it seemed to load the text and ...
Riham Nour's user avatar
0 votes
1 answer
1k views

CS50 dictionary.c problem with hashtable

Im having troubles with the hashtable in pset5, in the part where you check wether a word is in the dictionary. My code looks as follows: bool check(const char* word) { int n = strlen(word); ...
Wouterbieze's user avatar
0 votes
1 answer
114 views

error: expected expression. Compling problems!

Right where it says " <= 'Z' " the complier puts a ^ to the < sign and says error: expected expression. I included . I have no idea what is wrong with this statement! int hash_func (char* key) {...
Fijj's user avatar
  • 29
0 votes
1 answer
39 views

Segmentation error with array of nodes

I don't understand why I am getting segmentation error. Is it because I'm setting the array to NULL? Though if I don't set it to NULL then the head of the list will always keep the value of zero. ...
Kareem's user avatar
  • 3
0 votes
2 answers
138 views

Hash tables running time

In the week 6, it was said for hash tables that - "We could even combine names and birthdays somehow to create a larger hash table that’s even more uniform and have smaller chains, and be even faster" ...
hagrawal7777's user avatar
1 vote
2 answers
1k views

how to check if just the load function is implemented correctly?

I've just started this pset and only implemented load. So how do I know if my load function actually loads the dictionary and there are words in the hashtable without implementing the other functions ...
VishG's user avatar
  • 13
0 votes
1 answer
74 views

How do I pass back the location of my loaded dictionary?

I have (hopefully) loaded the dictionary correctly, but I'm not clear on how to identify its location in memory without changing the declaration of the load function? More concretely, in my code for ...
Richard's user avatar
  • 166
6 votes
1 answer
103k views

How to fix the "conditional jump or move depends on uninitialized value" valgrind error?

Need help again. I've got my linked list working. It copies a list of words from a file into a linked list. Now I want to make a hash table so that all words starting with the letter 'A' go into a ...
jzz's user avatar
  • 65
0 votes
1 answer
409 views

Am I creating an array of pointers or an array of structs?

I've read an answer to a similar question about node* new_node = malloc(sizeof(node)); and how it allocates memory for the pointer plus all the data contained within the struct as it was declared ...
Erin Magner's user avatar
1 vote
1 answer
954 views

Pset6: Is it possible implement a 3D Hash table Matrix?

It might be too early on for me to ask questions in this problem set, as I am just getting started with load. I was looking up Hash Functions, and they look a little cryptic to me. Is it possible to ...
Erin Magner's user avatar
0 votes
1 answer
32 views

How are associative arrays like hash-tables?

In week 9 lecture, David said: An associative array is one in which you can store key value pairs where the key is not necessarily a number. It could in fact be a string, a word. And so this ...
RexYuan's user avatar
  • 309
1 vote
1 answer
500 views

malloc an array - hash table - Pset 6

Initially i had no problems implementing my hash table during the load function. however when it came time to check for errors, i couldn't access my hash table in order to traverse my linked list. I ...
MJay's user avatar
  • 11
1 vote
0 answers
110 views

Is hash table a type of dictionary?

In week 7 shorts for trie it is said that "a dictionary is a type of data structure that maps a key (usually string) to value". So is hash table considered a dictionary too?
Avi's user avatar
  • 93
0 votes
1 answer
258 views

pset6 load seg faulting when accessing malloc'd node

I need some guidance on where I'm going wrong here. GDB runs fine until I try to access the "next" property of a node to see if it's NULL. Am I just confusing how the node structure works? My ...
gedm's user avatar
  • 1
0 votes
1 answer
110 views

PSET6: Sorted List?

I just finished pset6 following the videos of Zamyla and the section. At the end I realized that my code implements a sorted linked list (via strcmp) but then I don't take advantage of that in my ...
Juan Carlos Piñeros's user avatar
2 votes
2 answers
2k views

implementation of hash table

I have been having trouble with the implementation of the hash table and linked lists. I don't know if I am on the right track or not, but I think my main problem is not knowing how to automate the ...
sousheel's user avatar
  • 149
1 vote
2 answers
379 views

Why should we mod a hash value by the size of the hash table?

Week 7 Short on Hash Table provides the following suggested hash function: int hash_function (char* key) { // hash on first letter of string int hash = toupper(key[0]) - 'A' ; return hash ...
Allen Mark Brown Jr's user avatar
0 votes
1 answer
150 views

What is wrong in this implementation of hash table?

The following implementation for insert() function that inserts input into a hash table namely first each of which elements are pointers to a linked list works well. // takes the number to be ...
Aditya Kashyap's user avatar

1
2