FOUNDATION · WEEK 02

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.

13 study sections26 illustrations3 resources
Start Week 2 →

Study sections

Follow the order or choose a section
01

Search 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…

2 illustrations
02

Search 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…

3 illustrations
03

Maximum 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…

2 illustrations
04

Initialize 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…

2 illustrations
05

Local 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…

2 illustrations
06

Count 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…

2 illustrations
07

Group 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…

2 illustrations
08

Word 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…

2 illustrations
09

Keep 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…

2 illustrations
10

Two 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…

2 illustrations
11

A 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…

2 illustrations
12

Pseudocode: 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…

2 illustrations
13

Pseudocode 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…

2 illustrations