A Common-Sense Guide to Data Structures and Algorithms, Second Edition: (pg460)

Hello! Thanks for the great book.
I was attempting the Trie (chap 17) exercises and for number 4 the solution provided for the autocorrect function does not work as intended. I made sure to double check my code, even copied and pasted and the function would just return the first item in the list of words regardless of the current node that was sent to it. I hope you get a chance to look at it.
Update: It works if the collectAllWords function, explained earlier in chapter 17, is updated to start from the currentNode being passed from the autocorrect function. How this collect function was set up it would always start from the root of the Trie even if the correct node was passed.

#errata
/book-a-common-sense-guide-to-data-structures-and-algorithms-second-edition by @jaywengrow

Hi,

Thanks for submitting this! (And sorry for the late reply.)

I’m running this on my computer and it seems to work, but maybe I’m missing something. Can you please provide me with the exact complete code you’re running?

Thank you,
Jay

Hello,

I was also struggling with this exercise, but I think what happens is that we have to explicitly reset the words list to an empty list if we run the collectAllWords method before running the autocorrect method. What I mean is:

in the autocorrect method, instead of having
return wordFoundSoFar + self.collectAllWords(currentNode)[0]

we could have
return wordFoundSoFar + self.collectAllWords(currentNode, words=[])[0]

Does this make sense? Thanks.

Hi - thank you for this! You are both correct, and I will clarify this in the book’s next version.