Skip to main content
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
  • 21k
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
  • 21k
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
  • 21k
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
  • 69.1k
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
  • 69.1k
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
  • 69.1k
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
  • 21k
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
  • 69.1k
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
  • 69.1k
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
  • 69.1k
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
  • 21k
1 vote
Accepted

pset5: working, no leaks but many errors says valgrind in my recursive trie

Those valgrind errors are telling you that you malloced some memory (which means that you were given some memory to use) but that you then tested that memory for some condition without having ...
curiouskiwi's user avatar
  • 18.7k
1 vote

Stuck on the unload() function. Possibly wrong logic used on load() and check() using tries

sizeof(word2) will give you the size of a pointer on your system, in bytes, most likely 8 for a 64 bit system. You probably meant strlen(word2). The comparison makes no sense in the initialisation ...
Blauelf's user avatar
  • 21k
1 vote
Accepted

Speller: Trie'ing and trie'ing to fix this seg fault, but to no avail

It's really a simple problem, but you're probably looking for it in all the wrong places. ;-) Think about what happens when the code reaches the end of the dictionary, paying special attention to ...
Cliff B's user avatar
  • 69.1k
1 vote
Accepted

All words misspelled? Speller.c

You have the problem very similar to this one. You check if (i == strlen(word) - 1 && trav->is_word == false) { return false; } Let it be word "a". You are now in the ...
obesman's user avatar
  • 1,139
1 vote
Accepted

Pset5: Check returns all as misspelled (trie)

The problem is that you do not check is_word of the current node as your loop is over at the moment when your are in the right place. let's suppose it is word "a". So n= strlen(a) = 1. You check trav ...
obesman's user avatar
  • 1,139
1 vote
Accepted

pset5 : Speller: Trie: Segmentation Fault

Ok, guys, i understood where is the problem in my code. The problem was that fgets() actually adds a newline character at the end of the word. So the length of the string is increased by 1(if it was '\...
ymdatta's user avatar
  • 13
1 vote
Accepted

Only last word in dictionary is spell checked correctly

if (cursor->children[alpha_index] == NULL) { cursor->children[alpha_index] = malloc(sizeof(node)); } // advance to next node in trie ...
DinoCoderSaurus's user avatar
1 vote
Accepted

check50 possessives and substrings

The check50 is saying that possessives aren't being handled properly, but that could be in "load" or "check". Possessive's are handled in the "load" function too. You seem to only be sharing the "...
Rachel's user avatar
  • 75
1 vote

check50 possessives and substrings

It is possible both failures have the same cause. What does the program do if it "runs out of word" before it "runs out of trie nodes"? * You can construct a small test taking a hint from the ...
DinoCoderSaurus's user avatar
1 vote

Speller Load gives segmentation fault

I did not "see" a potential seg fault by reading the code, so I ran it and it did not give a seg fault. Perhaps it's a problem in check? Best to run it with debug50 to see what is really going on. ...
DinoCoderSaurus's user avatar
1 vote
Accepted

pset5 unload trie

You free the node even if it has children. You should first destroy any non-NULL children, and then free the current node. No while loop required, just a single loop over all the children, calling ...
Blauelf's user avatar
  • 21k
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
  • 69.1k
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
  • 69.1k
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
  • 69.1k
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
  • 69.1k
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
  • 69.1k
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

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