Hot answers tagged

9 votes
Accepted

pset5 root node defitnion (trie)

It's actually a simple fix. Since it's something that you would either know or not know, here it is. You declare the pointer variable as a global outside of a function, but you malloc space for it ...
Cliff B's user avatar
  • 68.4k
3 votes
Accepted

CS50 pset5 Memory Leak (trie structure)

for (int i = 0; i < 26; i++) You have 27 elements (a-z and '), so <=26 or <27 would be appropriate.
Blauelf's user avatar
  • 20.9k
3 votes
Accepted

pset5:(speller) Check function does not correctly identify misspelled words

check: tolower(word[i]) returns the lowercased ith character in word. You never use the value, you might want to assign it. Or remove this loop and later use tolower(word[i]) instead of word[i] when ...
Blauelf's user avatar
  • 20.9k
3 votes
Accepted

Speller(trie) / my code can't handle most basic words and substrings properly

current_node = root; should be within your while loop, so you start at the root for every new word. Otherwise a dictionary of cat caterpillar would end up with two words, cat and catcaterpillar. ...
Blauelf's user avatar
  • 20.9k
3 votes

PSET5 speller - I cannot understand tries at all

Don't feel bad, it took me a little while to wrap my head around the concept originally. ;-) A trie is essentially a tree representation of a bunch of words. The root of a tree and every node can ...
Cliff B's user avatar
  • 68.4k
2 votes
Accepted

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

suppose we are to implement speller using an array instead of a hash-table or a trie. a main problem that we have is that we don't know the number of words in the dictionary in advance (yes, we know ...
kzidane's user avatar
  • 17.7k
2 votes
Accepted

pset5 trie: What is the boolean-data value in the root node if the dictionary has one-letter words?

The trie starts at one root node. This node will always have the is_word bool as false because the root node doesn't actually represent a letter. For a one letter word, say a, you would first move one ...
Cliff B's user avatar
  • 68.4k
2 votes

Pset5 unload trie 244 bytes lost

Your code isn't freeing recursively. It should keep on going down the tree while children[i]!=NULL, only freeing the node when that condition isn't met anymore. It then returns up the tree, freeing ...
ronga's user avatar
  • 1,415
2 votes
Accepted

Pset5: trie check outputs 18000 out of 19000 words in austin powers

You have a very narrow but very deep trie. Each word is supposed to start at the base of the trie. Where does the second word start loading in the trie? The third? After that? ;-) If this answers ...
Cliff B's user avatar
  • 68.4k
2 votes
Accepted

PSET5 - Trie Check Segmentation Fault

It's a common problem. The problem lies in load(), where you have created a "shadow variable." A shadow variable happens this way: First, the original variable is created, either earlier in main or a ...
Cliff B's user avatar
  • 68.4k
2 votes

Pset5 - Check not returning expected output

Please state in which way your output differs. Number of loaded words? Number of mismatches? feof does not tell you whether you are at the end of the file. It tells you that you are at the end of the ...
Blauelf's user avatar
  • 20.9k
2 votes
Accepted

pset5 2017 unload() trie segmentation fault and undefined behavior

Couldn't do a full, in-depth analysis because I would need to see the node struct declaration and all of the involved functions. However, here's a somewhat common issue. Look at the following code: ...
Cliff B's user avatar
  • 68.4k
2 votes
Accepted

Pset5 trie unload -recursive function does not free memory

Think carefully about what the code is doing. It checks if a pointer is null, and if so, it will free that node. In other words, it will free a nonexistent node - a do nothing operation. OR, if the ...
Cliff B's user avatar
  • 68.4k
2 votes
Accepted

PSET 5 - how to use the least memory - the magic trie sauce

The people at the top of speller bigboard, to get incredibly low values in reported memory usage, use other kinds of memory than stack or heap. It requires picking a maximum dictionary size, though, ...
Blauelf's user avatar
  • 20.9k
1 vote
Accepted

Pset 5 all words misspelled

The problem lies in the load() code: else { int index = getIndex(c); nextNode = ptr->nodes[index]; if (nextNode == NULL) nextNode = malloc(sizeof(node)); ...
Cliff B's user avatar
  • 68.4k
1 vote
Accepted

PSET5 - Why am i getting segmentation fault after correctly finding some mispelled words?

It's an issue of ordering in check(). The code checks to see whether crawler == NULL as the last operation in the for loop. This means that crawler can be set to NULL, and can try to return is_word ...
Cliff B's user avatar
  • 68.4k
1 vote
Accepted

PSET 5: Dictionary.c, Trie structure, Check/Load, All words misspelled

You're on the right track - there is something wrong in load(). It's a subtle logic problem. When you process each character, the following line is processed: strider = strider->children[...
Cliff B's user avatar
  • 68.4k
1 vote
Accepted

pset5, load successfully but seg fault in check

If the seg fault you described is occurring on the line if (checker->children[position] == NULL) it's almost certain that checker itself is NULL or contains garbage data (was it properly ...
Cliff B's user avatar
  • 68.4k
1 vote
Accepted

pset5 loading too many words with trie

Interesting interaction. The code is dependent on finding \n to mark the end of a word in the trie. The problem is that the ASCII code for \n is 10. The code that looks for \n comes after the letters ...
Cliff B's user avatar
  • 68.4k
1 vote
Accepted

pset5 load with tries, not permanently creating connections between nodes

Look at your condition in your second while loop. Why would it not create a node? while (i < wordlen) After iterating through the first word 'cat', it start iterating over 'caterpillar'. The ...
Darc Nawg's user avatar
  • 151
1 vote
Accepted

Implementing a trie. Updated load function in dictionary.c causes more problems with valgrind

I'm trying to figure out the best way to tell you this so that you can find it on your own, without just telling you where the problems lie. The good news is that the total memory leak code fix is ...
Cliff B's user avatar
  • 68.4k
1 vote
Accepted

Pset5 600 out 644 words misspelled. What am I missing?

There are two major problems with the code. First, neither load nor check are coded to handle apostrophes. Because of that, the value of index will be set at the ascii value of an apostrophe every ...
Cliff B's user avatar
  • 68.4k
1 vote
Accepted

pset5 dictionary.c check or load issue

Here's a big red flag. The following line is near the bottom of the check() function. next_node -> is_word = true; In every dictionary word that it checks, it will set is_word to true for ...
Cliff B's user avatar
  • 68.4k
1 vote
Accepted

Pset5 all words in text mispelled: cannot figure out if the problem is in load or check function

1) fgetc will return each character as it appears in the file. Are you sure that the words in the text file are null terminated? (i don't think they are, not unless something changed a lot in the text ...
Irene's user avatar
  • 1,687
1 vote

Segmentation fault (core dumped) in speller (trie)

It seems you forgot to initialize your children array to NULL, which is why GDB shows you a segfault occurring there. While you're at it, you might want to initialize is_word to false as well. Finally,...
ronga's user avatar
  • 1,415
1 vote
Accepted

Pset5 trie problem with load: persisting segmentation fault

I see several problems. First, look at this: if (c == '\'' && c !='\n') The only time this will ever be true is when you see an apostrophe. No letter will ever get past this. Perhaps you ...
Cliff B's user avatar
  • 68.4k
1 vote
Accepted

PSET5 What LOAD really supposed to do?

Yes, the dictionary file is expected to be a file that contains a sorted list of words, one per line. Your mission is, indeed, to create in the LOAD function, code that will take those words and ...
Cliff B's user avatar
  • 68.4k
1 vote
Accepted

Segmentation fault in pset 5

There are two major problems in the code. First, look at this: node* root = (node*) malloc(sizeof(node*)); The parameter for malloc is the size of the object that needs to be allocated. ...
Cliff B's user avatar
  • 68.4k
1 vote

seg fault in pset5 check50 speller.c

check50 runs in a slightly different environment that can produce seg faults that won't show up in the IDE. However, the seg fault is showing that there's an error somewhere in the code. Also, it's ...
Cliff B's user avatar
  • 68.4k
1 vote
Accepted

Load giving segmentation fault

Your code doesn't handle apostrophes. If the dictionary file has a word with an apostrophe, the index value generated is -58, so trav->children[index] generates a seg fault. If this answers your ...
Cliff B's user avatar
  • 68.4k

Only top scored, non community-wiki answers of a minimum length are eligible