What makes an algorithm good?
An algorithm is a finite, precise procedure for solving a problem; it should be correct, terminating, clear, efficient, and generally applicable.
Study 8 Fundamental Programming Techniques with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.
What makes an algorithm good?
An algorithm is a finite, precise procedure for solving a problem; it should be correct, terminating, clear, efficient, and generally applicable.
What is a loop invariant?
An invariant is a condition that remains true at a particular point during every loop iteration.
How do Python collections differ?
A list is ordered and mutable; a tuple is ordered and immutable; a set stores unique values; a dictionary maps identifying keys to values.
What does a function contract specify?
A function contract specifies its inputs, returned output, side effects, and possible errors.
Why return results instead of printing them?
A calculation function should generally return its result rather than print it, separating computation from presentation.
How do sorted() and list.sort() differ?
sorted() returns a new list, whereas list.sort() changes the existing list in place.
Why use with for file access?
A with statement closes the file automatically, even if an exception occurs during file processing.
Why catch specific exceptions?
Catch specific exceptions so expected failures can be handled without hiding unrelated programming errors.
What do boundary tests examine?
Boundary tests cover cases such as empty collections, zero, one item, and minimum or maximum values.
What does a traceback reveal?
A traceback identifies where execution failed, but not necessarily where the incorrect value was originally created.
How is the word-frequency program modular?
The word-frequency program extracts words, counts them, orders the results, formats a report, and handles file access and user interaction in separate functions.
How are ties resolved in top_words()?
For equal word counts, top_words() orders words alphabetically, making the report deterministic and easy to test.