Homework 2 (Word Ladder / N-grams) FAQ

Q: How do I construct a compound collection? It doesn't compile.
A: You need a space between nested <>.
Vector<Vector<int>> foo;    // no
Vector<Vector<int> > foo;   // yes
Q: Why can't I make a nested collection that is a Set or Map of other collections? AKA, why am I getting this error?
no match for 'operator<' (operand types are '....
A: In order for an element to go into a Set or Map, it must have some kind of ordering so that the Set/Map can sort them into order. Collections like Vectors or Stacks don't have a sorting to them, so they can't be put into a Set or used as a key in a Map. If you want this kind of nesting, you could use a HashSet or HashMap.
Q: When I try to construct my compound collection, it gives a strange compiler error about "no match for 'operator <'." What is that?
A: If you use a collection that tries to arrange their elements or keys into order, it needs to be able to compare the elements to each other. It uses the standard relational operators such as < to do this. So you can't store an element type that doesn't have a < operator and therefore cannot be ordered. Choose a different type of compound collection.
Q: In Part A, am I allowed to use a Lexicon?
A: Yes, though you are not required to do so.
Q: In Part A, why is my program veeeeeeery slow?
A: Usually this happens for one of two reasons: Either you have chosen the wrong data structure somewhere, or you have not properly followed the pseudocode algorithm we have you. A common bug is that students will loop over the entire dictionary to look for words. You should not need to do that. The purpose of the dictionary is to look up words, to test whether something is a valid word or not; not to loop over. If you want to loop over all possible "neighbor" words that are one letter away from a given word, do this by looping over the indexes of the string and over the letters a-z, as described in the pseudocode; not by looping over the dictionary.
Q: In Part A, why does my program spit out a VERY long (20-30+ word) ladder even for simple cases?
A: Maybe you're accidentally adding words to an existing collection rather than making a copy of it and adding to the copy. Run with a very small input, then print out your collections along the way and make sure everything is what you expect.
Q: In Part B, how do I get a random number?
A:
#include "random.h"
...

int r = randomInteger(min, max);   // inclusive
Q: In Part B, how do I get a random element of a collection?
A: If it's an indexed collection, such as a Vector, just pick a random index and then go access that index. If it doesn't have indexes, like a set or queue, pick a random index based on the size, and then advance forward (e.g. in a foreach or while loop) that many times and grab the element found there.
Q: Do I have to use the exact collections the spec says to use? I want to use a different one.
A: Follow the spec.
Q: I can't see this assignment in the list of assignments to turn in. How do I turn in the assignment?
A: Try opening an Incognito Tab and opening the Paperless system in that tab. Did the assignment show up?
Q: When I try to turn in the myinput.txt file, the system doesn't display it. Did the turnin system accept my file?
A: Check the page that displays information about your past submission. Do you see myinput.txt there? If so, we received it successfully. If not, you may need to submit again. Sometimes this issue comes from the input file being very large (over ~2mb).
Q: Can I use one of the STL containers from the C++ standard library?
A: No.
Q: I already know a lot of C/C++ from my previous programming experience. Can I use advanced features, such as pointers, on this assignment?
A: No; you should limit yourself to using the material that was taught in class so far.
Q: Can I add any other files to the program? Can I add some classes to the program?
A: No; you should limit yourself to the files and functions in the spec.
Q: In Part B, what should go in my myinput.txt file?
A: Copy/paste a fun source of text from the web. For example, grab lyrics from your favorite band, or text of a book or movie script you like, or just make up any text you want.
This document and its content are copyright © Marty Stepp, 2014. All rights reserved. Any redistribution, reproduction, transmission, or storage of part or all of the contents in any form is prohibited without the authors' expressed written permission.