The lecture first keeps the current best marks card in a separate place. Replacing it with a better card is the same idea as updating a Max variable. Keeping just the score saves the value but loses the identity of the card; a later lesson adds that information.
If the dataset is empty: report "No maximum"
Otherwise initialize Max from the first actual value
For every remaining value v {
if (v > Max) {
Max = v
}
}
Report Max
A comparison with Max changes over time because Max changes. This differs from a fixed filter such as “score > 90”. It is also a replacement, not an accumulation: Max = Max + v would compute something else.
Use the stored LetterCount field for the word-length task: the comma on Vedanayagam, is not another letter. The shopping tutorial reports a maximum bill of Rs 4174; it is a maximum individual bill, not the total revenue of a store.
After each visit, Max is the maximum of the values already inspected. A new value either beats that maximum or cannot change it. After the last visit, the inspected set is the entire input. Card order can change the intermediate updates, but not the maximum value.
Try it yourself
For 12,8,15,9, what Max values are stored after each visit?
Show explained answer
12,12,15,15. Only a new larger value replaces the current maximum.
Try it yourself
Why not stop as soon as the first high score is seen?
Show explained answer
A later score might be higher. To prove a maximum, inspect all candidates unless a known absolute upper bound rules out improvement.
Try it yourself
What is the maximum Mathematics mark in Scores.pdf?
Show explained answer
97. Two records share it: Rahul (11) and Deepika (23).
Try it yourself
Is the longest printed token necessarily the one with largest LetterCount?
Show explained answer
Not if the printed token includes punctuation. Use the field definition and the recorded or verified letter count.
Source: Lecture 2.2; Tutorial 2.1. Small teaching datasets and diagrams are prepared for these notes; lecture and tutorial totals are identified explicitly.