Search, compare and keep the right information
Learn early stopping, maximum values, group counts, ties, two-pass filtering and pseudocode with the supplied course datasets. Build on the card-processing patterns from Week 1.
Study sections
Follow the order or choose a sectionSearch and stop: conditional termination
In Week 1 we usually visited every card. Sometimes the question only asks whether any matching card exists. Once you find one, further…
02Search within ordered words and sentences
“First verb in the third sentence” is an order-sensitive question. Unlike counting or finding a maximum value, it cannot be answered co…
03Maximum in one pass: keep the best so far
To find a maximum, remember the best value seen so far. Compare each new value with it. Replace the remembered value only when the new…
04Initialize maximum, minimum and result variables safely
Initialization is part of the algorithm, not a decoration. A wrong starting value can survive every comparison and become a result that…
05Local counts: longest sentence and longest grouped run
Sometimes the value to maximize is not printed on one card. You must first build a local count across several cards, then compare it wi…
06Count by category and track the largest frequency
A record’s category may repeat much later in a shuffled pile. Keep one persistent count for each category, rather than resetting whenev…
07Group totals: maximum revenue is a different question
A group count adds 1 per record. A group total adds an amount from the record. A shop can have fewer bills yet more revenue if those bi…
08Word frequencies: normalize first, then count
To count occurrences of a word, decide what “the same word” means. Without a consistent rule, capital letters and punctuation can creat…
09Keep the winning record and handle every tie
Knowing the highest mark is not enough when you need to name the students who earned it. Keep the relevant record ID together with the…
10Two passes when the second decision needs final counts
Combining work into one pass is useful when it is correct. Some decisions need information that is not available until the entire first…
11A flowchart for maximum values and owners
A maximum-finding flowchart is a filtered iteration whose update condition compares the current card with a changing variable. Its proc…
12Pseudocode: assignment, fields and while blocks
Pseudocode writes a procedure as structured text. It is easier to edit, compare and discuss than a large picture, while keeping the sam…
13Pseudocode with filters, if–else and nested conditions
A while chooses whether to repeat a block. An if chooses whether to execute a block during this visit. An else chooses the alternative…
