Q: I'm having a hard time with recursive backtracking. What should I do?
A: Take advantage of the examples we've seen in lecture and in section. In particular, take some time to understand the permutations and 8-queens examples from lecture. Notice how the eight queens problem stops after finding one possible solution, but the permutations example finds all possible solutions, like your program should. From the section handout, subsets, make-change, and sum-of-squares are some especially applicable functions. There are also some notes on recursive backtracking by Stuart Reges, available on the lecture section of the website.
Q: How am I supposed to limit no more than a certain number of words?
A: This is a harder aspect of this assignment, so you shouldn't tackle it first. Get your code working so that it will print all appropriate anagrams regardless of how many words long they are. Once you have handled this somewhat easier problem, then take a look at only outputting the anagrams with no more than max words.
Q: Should my code keep looking for anagrams once it exceeds max?
A: No. It is inefficient for your code to keep running down paths once you know that they won't yield a viable solution.
Q: Should we only output anagrams that use up all of the letters in the given word/LetterInventory?
A: Yes. The writeup explains, "An anagram is a word or phrase made by rearranging the letters of another word or phrase". For example, [love, lace] would not be an appropriate anagram for the string Ada Lovelace because it doesn't use the letters ada.
Q: How can I tell if my program is finding all of the correct anagrams?
A: Testing! Just like always, it's best to start small and then work your way up from there. Start off by using the small file dict1.txt as your dictionary since it's small enough to check which of the words can be made from a given phrase just by looking at it. Once you've convinced yourself that your program works with this small dictionary, you should move on to the larger ones. The Output Comparison Tool on the Homework page of the course website shows output for various phrases from various dictionaries. Make sure to take advantage of this valuable resource! Remember that the tests from the comparison tool are not exhaustive, but it's a good place to start.
Q: How do I debug my recursive function?
A: Try using a cout statement to find out what the anagram looks like at certain points in your program. Try before and after your recursive step as well as in your base case. You might also find the IDE's debugger useful.
Q: My recursive function is really long and icky. How can I make it cleaner?
A: Start off by making sure you can identify the base case and the recursive case clearly. You want to practice recursion "zen" by writing good base cases. Don't use "arm's length" recursion, which is when you bury your base case inside of what should be your recursive call path. Make sure you're not making any needless or redundant checks inside of your code.