Lesson 1 of 6 · Algorithms without code
Write an algorithm someone else can follow
8 minute lesson · 3 checks along the way
Your goal for this lessonTurn a scientific task into explicit inputs, steps and outputs.
In this lesson 3 sections · 3 checks
Using archive links & definitions
Words with a dotted underline open a short definition right here in the lesson.
Read & understand
A procedure is more than a goal
An specifies a sequence of operations that transforms inputs into outputs. “Find the average temperature” states a goal but leaves decisions unresolved: which readings, which units, what counts as missing and what happens if none are valid? Clear steps make those choices visible before any programming language is involved.
For a fictional exercise, begin with the readings 4, missing and 8 in one stated unit. Select valid readings, add them, count them and divide the sum by the count. The result is 6 from two valid readings. Keep the count as part of the output so the mean does not conceal coverage.
Check 1 of 3
10 pointsUse the reading above. You can try again without losing points.
Read & understand
Trace the state by hand
A running sum and a valid-count variable describe the algorithm’s state. Start both at zero. Reading 4 changes them to 4 and 1; the missing entry leaves them unchanged; reading 8 changes them to 12 and 2. The final division produces the same result as the manual calculation.
If the valid count remains zero, dividing by it is not a meaningful average. The procedure should return an explicit no-valid-data result. This is a scientific decision about the output’s meaning, not merely a way to avoid a programming error.
Trace the state: fictional readings
Original teaching diagram. Input sequence. 4, missing, 8. Skip missing values. Final state. Sum = 12; count = 2. Mean = 6. If count is zero, report no valid data rather than inventing a measured zero.
Open full-size diagram in a new tab: Trace the state: fictional readingsCheck 2 of 3
10 pointsUse the reading above. You can try again without losing points.
Read & understand
Make assumptions inspectable
A second person should be able to reproduce the result from the written steps. Specify whether units are converted before combining values, whether repeated timestamps are allowed and how quality flags are handled. Different valid scientific questions can require different algorithms.
Test a small example with a known answer and an edge case such as all entries missing. Then compare the written procedure with the implementation. A program that runs without crashing may still implement the wrong rule; tracing a simple case helps expose that mismatch before applying it to a large dataset.
Check 3 of 3
10 pointsUse the reading above. You can try again without losing points.
Put it together
Your lesson progress
Each check connects to a part of the story. Complete all 3 to earn your 25-point lesson bonus.
Explore further · Optional
Go to the source
Explore the evidence behind this lesson. These optional readings and videos open in a new tab.