Ready to begin
Choose Next step to follow the actual course records.

A procedure lets the caller delegate a well-defined task. SearchBirthday(Target, OtherCards) returns true if at least one card in OtherCards has the target day and month; otherwise it returns false. For an individual student search, OtherCards must exclude that student. The caller can pass only later unprocessed cards to avoid repeated pairs.
Trace the records, compare the methods and watch what changes. Back and Reset let you try again.
Ready
Choose Next step to follow the actual course records.
Start with Next step. Predict what changes before reading the explanation.
Procedure SearchBirthday(Target, OtherCards):
for each card Y in OtherCards:
if BirthdayKey(Y) == Target:
restore any required order and markers
return true
restore any required order and markers
return false
End ProcedureReturning false inside the loop after the first non-match is a bug: a later card may match. Returning true after a genuine match is valid for existence. Early return must still honour the restoration part of the contract.
| Contract | What the helper may change |
|---|---|
| Answer only; free reordering | It can reorder cards if the caller does not rely on order |
| Preserve markers / processed status | It can reorder where allowed, but must keep each card’s status |
| No observable side effects | Restore original values, markers and exact order |
In the lecture, sideways cards mark students already processed. Losing that orientation makes the caller forget which outer cards are finished. A correct Boolean alone is not enough. The caller may rely on guarantees written in the contract, but must not assume stronger guarantees that were never promised.
The target birthday is a parameter. A marked deck can also carry a parameter implicitly: the mark tells the helper which position or card matters. Written code is usually clearer when it names the target, eligible records and preservation rules explicitly.
Why is SearchBirthday called with the selected student still in OtherCards wrong?
The student always matches their own birthday, so every search would report true even when no second student matches.
Can a helper return the correct answer and still violate its contract?
Yes. It may lose processed markers or reorder words when preservation was promised. The caller’s later work can then fail.
A helper checked three non-matches out of 29 cards. May it return false?
No. A false result requires exhausting the eligible cards. A true result needs only one genuine match.