I haven't written any code yet, although I've written pseudocode for this problem, and I keep coming back to the issue of base case. I built a trie and now want to recursively unload it. I think I've got a handle on the recursive statements but my stumbling block is initializing "current" or "index" without starting all over again each time I recursively call my function. I've avoided looking at other answers to this, because I want to try and work it out, but if anyone can ask question that will help me think about this properly, that would be a big help.

• Suggest that you ask on one of the more interactive forums, like CS50 Slack. Jun 30 '17 at 21:50

It may help to visualize the trie in your head (or on paper) to think about how you want to go about deleting each node. I think Doug Loyd explains it pretty well in his trie short where he describes the trie as a sort of upside down tree where the root node is at the top which then branches out through its children to eventually reach the leaves which are the last nodes (with true or false bool in this case).

So you might want to think about the base case as running out of new nodes in each specific branch to delete. For example if you have two words in you trie say "at" and "for", your root node's children would be all NULL except for entry "a" and "f". Therefore a base case could check that any index in a node is NULL because that would either mean no word starts with that letter say "b", or that the word is in fact finished. In the word "at" your recurive function could call itself until it finds that there is no node extending from "t" in which case it will delete nodes all the way up the branch from the leaf up by the nature of how recursion works.

Of course it gets a bit more complicated when there are multiple words that start with the same letters "at" and "arm", but the same principle of recursion checking for NULL as the base case should work the same as the function will travel down the whole "arm" series of letters, delete "m" node, but will then have a choice between going to the "r" or "t" node first, delete that whole branch (and possibly any others down the line), before returning to the node it didn't choose before and continuing the process.

It is your choice how you want to implement this, but I figure it should work any way you decide to choose the next nodes to delete in the trie as long as you are consistent, for example starting at "z" words and always picking last characters in the alphabet first or vice versa.

And as for indices, you could just start from the left most or the rightmost side of your trie (assuming you implemented in alphabetical order) and decrement or increment as needed to go through all values of the alphabet and the apostrophe. If you already completed the check() and load() functions then you have an idea about how you structured your trie, and can build from there. Hopefully that makes sense without being confusing, and hopefully I am right about how recursion in this case could work, but I may be wrong at a few points since I'm not that experienced with it myself!