Reasoning about Code
Think about the following problems and discuss what kind of sequence would most help represent the data. In Python, we have discussed a variety of kinds of sequences: strings, lists/tuples, sets, and dictionaries. For each of the following problems, state the type of sequence you feel best represents the data and explain your decision. Note, more than one sequence may make sense, so your justification is most important part of the exercise — how would you make use of your chosen sequence?
If you suggest a dictionary, clearly state what are the keys and values. If you suggest a sequence of sequences (e.g., a list of lists or set of tuples), clearly describe the type and purpose of the sub-sequences.
Student Registration
Consider the problem of building a registration program for a university that manages students wanting to register for courses, taking courses, and receiving grades for those courses. For these problems, you can either assume that student names are unique or that each student has a unique ID that can be used to easily lookup their name if needed (i.e., you do not need to come up with a complex solution to represent students uniquely, a simple string or number will do).
- a course contains a sequence of enrolled students
- a course contains a sequence of students on a waitlist to enroll
- a course contains a sequence of labs in which students are enrolled
- a course contains a sequence of students grades
Spell Checking
Consider the problem of writing a spelling checker. In addition to the kind of sequence(s) you would use, give pseudocode to solve the problem using those sequences (you do not need to write actual Python code).
- Checking: given a file of generally known, correctly spelled, words, a file of the user's personal words known to be correctly spelled, and a file of text, return those words in the text file that are not spelled correctly according to the words in the two files of known correctly spelled words.
- Correcting: given a file of words along with their common misspellings (one association per line) and a file of text, return those words in the text file that are not spelled correctly according to the words in the file of known correctly spelled words as well as suggested corrections (including none if the word is not found in the misspellings file).