r=89 mod 55=34; r=55 mod 34=21; r=34 mod 21=13 - three steps in, still not close to 0.
→
3
Six more steps
r=21 mod 13=8; r=13 mod 8=5; r=8 mod 5=3; r=5 mod 3=2; r=3 mod 2=1; r=2 mod 1=0. Nine steps total, versus three for GCD(48, 18) on similarly-sized inputs.
★
Why it must still stop
Every step's remainder r = a mod b is strictly less than b and never negative, so b strictly decreases toward 0 no matter how slowly - the argument that proves finiteness for every valid pair, not just the ones we happen to trace.
✓
ConclusionGCD(89, 55) = 1 after 9 steps - three times the work of GCD(48, 18), yet governed by the exact same guarantee.
💡
Key takeawayA trace only shows that one input stopped. Finiteness needs the general argument - `b` strictly decreases, bounded below by 0 - that covers every input, fast or slow.
One More Trap: "It Ran, So It Must Be Right"
GCD's proof was earned. Most code never gets that scrutiny - here's a bug hiding in plausible-looking code.
A student submits this attempt at "find the maximum value in a list."
It has never once produced a visibly wrong answer for its author - and
it still has a bug that fires on every single run.
MAX(A):
m = A[0]
for i = 1 to length(A):
if A[i] > m:
m = A[i]
return m
MAX · finding the hidden bug
Where MAX Actually Breaks
Array indices run 0 to length(A) - 1. Here's exactly where the loop bound goes wrong.
GoalShow why passing tests never proves an algorithm correct.
1
The loop bound
The loop says `i = 1 to length(A)`, letting `i` reach `length(A)` - one past the last real element, out of bounds on every run.
→
2
What happens
Depending on the language, that read either crashes immediately, or silently returns whatever value sits in adjacent memory.
→
3
Why nobody noticed
That garbage value is often small enough that `A[i] > m` evaluates false - so the final answer still comes out right, by luck, not by correctness.
★
The real lesson
The bug fires every run; whether it's visible is luck, not design. Passing tests can show the presence of a bug hides - never its absence.
✓
ConclusionThe fix: the loop should run `i = 1 to length(A) - 1`. Looking definite and effective is not the same as being correct.
💡
Key takeaway"I tested it and it worked" is never proof of correctness - a silent, harmless-looking garbage read is still a bug.
Spotting broken "algorithms"
Two More Broken "Algorithms"
Neither of these could actually be run, or handed to a colleague, and produce one guaranteed behavior.
GoalName exactly which property each one violates, and why.
1
"While true: print the next prime number."
There is always a next prime - this procedure is designed to never stop and never produce a final output. Violates finiteness.
2
"Divide the budget fairly among the clubs."
"Fairly" has no fixed meaning - equal shares? by need? by past attendance? Every reader could execute a different procedure. Violates definiteness.
★
The pattern to notice
A procedure with no stopping condition breaks finiteness; a procedure with an undefined word ("fairly," "look around") breaks definiteness - the two most common ways a "sounds reasonable" instruction fails.
✓
ConclusionTwo failures, two different properties - one has no way to stop, the other has no fixed meaning.
💡
Key takeawayWhen a procedure "sounds reasonable" but isn't an algorithm, it's almost always missing a stopping rule or a fixed meaning for one of its words.
FIND_ROOM: Idea and Pseudocode
Same five checks. Now on the actual case study, not a clean textbook example.
FIND_ROOM(directory, target):
for i = 0 to length(directory) - 1:
if directory[i].room == target:
return directory[i].location
return NOT_FOUND
Input: a well-defined array directory of room records, and a well-defined string target.
Output: either a well-defined location, or the sentinel value NOT_FOUND.
Definiteness:== on target is a precise, single-meaning comparison.
Finiteness: loop bound length(directory) - 1 is fixed before the loop starts.
CampusNav · worked example 1 of 2
FIND_ROOM: All Five Properties, Checked
Everything from the last slide, verified against the full rulebook.
GoalShow `FIND_ROOM` satisfies every one of the five required properties.
1
Finiteness
Loop bound `length(directory) - 1` is a fixed, known number before the loop even starts - no proof needed like GCD's, just a stated bound.
2
Definiteness
`==` on `target` is a precise, single-meaning comparison - no "look around" left anywhere.
3
Input & Output
Input: well-defined array `directory` and string `target`. Output: a location, or the explicit sentinel `NOT_FOUND` - defining the "not found" case is part of a well-defined output, not an afterthought.
4
Effectiveness
Array indexing and string equality are basic, executable operations any of us could carry out by hand.
✓
ConclusionAll five properties check out - this is what "look around until you find it" had to become before it counted as an algorithm at all.
💡
Key takeawayA precise loop bound plus one precise comparison operator turned a vague sentence into a provable algorithm.
CampusNav · worked example 2 of 2
Designing the "Not Found" Case
A well-defined output has to cover every input - including the one with no "real" answer.
GoalShow why the sentinel value is part of the spec, not an afterthought.
1
Why `NOT_FOUND` counts
Output only counts as well-defined if every valid input has a specified result, including "the room isn't in the directory." A version that silently did nothing, or crashed, would leave output undefined for that input.
→
2
Alternative: return -1
A rewritten `FIND_ROOM` returning `-1` instead of `NOT_FOUND` is the same algorithm - both are a single, well-defined sentinel value for "not found."
★
The real risk
It would only become a problem if `-1` were also a valid room index somewhere else in the system - making the sentinel ambiguous with real data, a definiteness risk, not a difference in algorithm.
✓
Conclusion`NOT_FOUND` and `-1` are both valid designs for the same algorithm - the only real danger is a sentinel that could collide with real data.
💡
Key takeawayA well-defined output must cover every input, including the ones with no "real" answer.
Common Mistakes
Confusing "an algorithm" with "a program." An algorithm is the language-independent idea - the steps themselves; a program is one specific implementation of it, in one specific language. FIND_ROOM above could be written in Python, Java, or C and still be the same algorithm.
Assuming any loop that eventually stops is automatically finite. It's tempting because, in casual testing, the loop did stop. But finiteness requires a proof that covers every valid input - like GCD's "b strictly decreases and can't go below 0" argument - not just the one run you happened to try.
"It ran and gave the right answer, so it's correct." Exactly the MAX bug above: one passing run proves nothing about the inputs you didn't try.
Key Words Today
Flowchart: a diagram form of an algorithm, using standardized shapes (start/end, process, decision) instead of text.
Trace: running an algorithm by hand, step by step, on one specific input, to check what it actually does.
Algorithm vs. program: the algorithm is the language-independent idea; a program is one specific implementation of it, in one specific language.
Loop bound: the specific, checkable condition that guarantees a loop cannot run forever - what finiteness actually requires you to state, not assume.
Precision Pays Off Beyond CampusNav, Too
This isn't only about one app.
Every later week in this course assumes you can write and read
pseudocode this precisely: complexity analysis (Week 3) needs a fixed
procedure to count steps on; recursion (Week 4) needs a precise base
case; every correctness proof after that starts from a procedure
precise enough to reason about in the first place. Skip this week, and
every one of those gets harder.
The same five checks also show up outside this course, in the same
words - search "algorithm properties" or "is this a valid algorithm"
in any textbook or interview-prep guide.
What This Week's Rulebook Cannot Do
We can now write CampusNav's "find room X" as a real algorithm and
check it against all five properties - precise input, precise output,
provably finite, unambiguous, every step executable. But suppose a
teammate proposes a completely different way to search the same
directory, and it also passes all five checks. We have no rigorous
way, yet, to say which precise algorithm is better - faster,
more scalable as the directory grows - only that both are legitimate
algorithms. "Precise" and "provably correct" are not the same claim
as "efficient."
Next Week
Week 2 leaves comparing two precise, correct algorithms unsolved. Week 3, Complexity Analysis, addresses it: Big-O notation, so we
can say precisely which algorithm is better, not just that both
qualify as real algorithms.
Where This Week Lives in CLRS
This week's ideas, mapped to the textbook.
This week's topic
CLRS 4th ed
The five properties of an algorithm
Ch 1
Pseudocode conventions (our house style vs. CLRS's)
§2.1-2.2 (style reference - INSERTION-SORT isn't taught until Week 5)
Euclid's GCD
§31.2
If you want to go deeper: §2.1's INSERTION-SORT is worth a first
read now for the notation alone; Chapter 31 (Number-Theoretic
Algorithms) covers what GCD is used for beyond this week, including
modular arithmetic and an early look at what becomes Week 9's fast
exponentiation.
Summary
Every real algorithm must satisfy five properties: finiteness, definiteness, input, output, effectiveness - fail one, and it's a suggestion, not an algorithm.
Pseudocode and flowchart conventions let us write and check these properties precisely, instead of just describing intent.
Algorithm ≠ program: the language-independent idea vs. one specific implementation of it.
Finiteness needs a proof (like GCD's shrinking b), not just one successful run.
New: Week 2 Check - a short graded exercise on the five properties, GCD, and FIND_ROOM, released now, due before Week 3 begins (see materials/assignments/week02-check.html).
Reading: CLRS 4th ed, Ch 1; §2.1-2.2 (pseudocode style reference); §31.2 (Euclid's GCD) - no exercises due, but read before Week 3.
Prepare: think of two different, both-correct ways you could search CampusNav's directory, and which one you guess is faster. Bring your reasoning to Week 3.
Thank You
SLOT 1: Title
notes: Remind the class of last week's "look around until you find it" line from the
course-contract session. Say: "Today we get the actual rules for telling a real
algorithm from a vague instruction that just sounds like one."
SLOT 2: Where we are
notes: Point at Week 2. Say: "Last week we felt why this course exists. This week we get the actual rulebook."
REWRITTEN: was a discussion warm-up; now teacher-delivered narration, also folds in the old end-of-deck Check Yourself Q1 (which property does "keep improving the guess" violate)
SPLIT for overflow: the resolution now gets its own slide
SLOT 3: Recap + open wound
NEW: Key Words Today, session 1
notes: Read each term aloud once. Say these four words get put to work in the next ten minutes.
SLOT 4: The pain (Act 1 / MOTIVATE), zero jargon. Split from the original combined pain+two-col slide: pain alone here, the two builds on the next slide.
notes: Do not say "definiteness" yet. Let the class feel the mess first; the two builds are on the next slide.
NEW: continuation - the two builds, side by side
notes: Do not say "definiteness" yet. Let the class feel the mess first.
SLOT 5: Cost of not knowing
SLOT 6: Driving question
SLOT 7: Learning outcomes
SLOT 8: Origin. Split into two: the older history here, Knuth's fix next.
NEW: continuation of Origin
SLOT 9: Core concept
NEW: Key Words Today, session 2
notes: Read each term aloud. Say: "Watch for these five ideas in everything for the rest of the hour."
Act 3 / BUILD: pseudocode and flowchart conventions
NEW: pseudocode conventions, continued (1 of 2)
NEW: pseudocode conventions, continued (2 of 2)
NEW: CLRS's own pseudocode conventions, as a second reference point (CLRS 4th ed, §2.1-2.2)
NEW: worked example in CLRS's own style, style reference only per SPINE.md (insertion sort content itself isn't taught until Week 5). Folds in the old Check Yourself pair on the two pseudocode styles.
SPLIT for overflow: the notation-vs-algorithm point now gets its own slide
MERGED: flowchart shapes + rules, folds in the old Check Yourself content on unlabeled diamonds and redrawing FIND_ROOM
What Is a GCD?, split: the definition alone here, the slow worked method next
NEW: continuation - the slow, brute-force method
Idea + pseudocode merged slide, matching the teacher-centric skeleton
NEW: dense worked example, GCD, simple tier
NEW: dense worked example, GCD, moderate tier (reuses the deck's existing verified 48,18 trace)
NEW: dense worked example, GCD, harder tier (reuses and completes the deck's existing 89,55 Fibonacci trace; folds the finiteness-proof content)
Rewritten: teacher-delivered exposition instead of a "find the bug" discussion prompt
NEW: dense worked example, MAX bug reveal. Folds the old "Where MAX Breaks" slide and the "Check Yourself: Tested vs. Proven" pair.
NEW: dense worked example, two more broken "algorithms". Folds the old Activity + Answers pair.
SLOT N-2: Worked example, idea + pseudocode
NEW: dense worked example, FIND_ROOM against all five properties
NEW: dense worked example, designing the sentinel value. Folds the old "Check Yourself: The Sentinel Value" pair.
SLOT N-1: Common mistakes, merged into one slide
NEW: Key Words Today, session 3
notes: Read each term aloud. Say: "These four, plus the five properties, are this week's whole vocabulary."