9/18: CSCI 100 Lecture Notes
Notes: Specs, Algorithms, Tracing
4 Key Terms
Spec — what the correct output should be (no implementation)
Algorithm — steps to get there (filter → order → select)
Program — algorithm implemented in code
Test — input + expected output vs. actual result
⚠ Running without errors ≠ correct (true even for AI-generated code)
Example Spec
Eligible = unseen + ≤5 min
Sort by score desc; tie → earliest ID
Return top 3 IDs; empty list if none eligible
Building Blocks
Sequence — ordered steps
Condition — if/else branching
Repetition — loop over items
State — what's remembered across iterations (e.g. "best so far")
Tracing = tracking state after each step, not just the final answer — pinpoints where errors occur
Algorithm vs. Procedure
Algorithm: terminates
Procedure: may run forever
(minor distinction, often used interchangeably)
Edge Cases
No eligible items → return null/empty, don't invent
Loops need clear stop condition