← Back to course
1/6
Week 02 · Algorithms in Pseudocode

Monday

Exact enough for a computer
// Exact steps, variables and expressions
⏱ about 20 min

Monday: Exact Enough for a Computer

Comet sticks a note on Beacon's paper prototype. It says: Water plants when dry. Tell Priya.

"Done," she says. "That is the whole program."

Wren reads it twice. "What do you notice? How dry is dry? Which plants? Tell Priya what, and how?"

Comet opens her mouth, then closes it. "Lena would just know."

Nova hovers beside the note, her cyan lights flickering. "Lena would," she says. "A computer follows exactly what you write, and nothing more."

"Then every step has to be exact," Comet says. She peels off the note and hands you a fresh pencil.

"Developer, help me write it properly this time."

What is an algorithm?

An algorithm is a finite set of instructions that accomplish a specific task.

Finite means the list of instructions has an end.

Algorithms are not only written in programming languages. They can be written in natural language, in diagrams or in pseudocode.

This course writes Beacon in pseudocode: short, exact lines that look like code, written on paper.

Way of writingExample for Beacon
Natural languageRead the water sensor, then show the number on the screen.
DiagramA box that says Read sensor, an arrow, then a box that says Show number.
PseudocodewaterLevel ← INPUT(), then DISPLAY(waterLevel)
WHICH WAY IS IT WRITTEN?
  • Read the question.
  • Tap your answer.
Lena's note says: "Check row two, then write the reading in the log."
Tomas draws three boxes joined by arrows: Take photo, Add date, Send.
Wren writes: lightLevel gets INPUT(), then DISPLAY(lightLevel).

Three building blocks

Every algorithm can be built from combinations of sequencing, selection and iteration.

Sequencing means doing each step in the order the statements are given.

Selection decides which parts of an algorithm run, based on a condition being true or false.

Iteration is a repeating part of an algorithm. It repeats a set number of times or until a condition is met.

This week is about sequencing. Selection comes next week, and iteration the week after.

WHICH BUILDING BLOCK?
  • Read the question.
  • Tap your answer.
Beacon reads the sensor, then stores the reading, then shows it, always in that order.
Beacon shows an alert only if the water level is low.
Beacon checks every row, one after another, until it has checked all twelve.
LENA'S LOGGING ROUTINE, IN SEQUENCE
  • ?Read the water gauge.
  • ?Write the row number next to it.
  • ?Move to the next row.
  • ?Write the number in the log.
  • ?Walk to the row.
WHY THIS EXERCISEIn sequencing, the order of the steps changes the result.
StatementTrue or false?
An algorithm is a finite set of instructions.?
Algorithms can only be written in a programming language.?
Every algorithm can be built from sequencing, selection and iteration.?
Comet's note "Water plants when dry" is exact enough for a computer.?
WHY THIS EXERCISEKnowing what makes an algorithm exact is the first step to writing one a computer can follow.
A finite set of instructions for a task is an ____.
Short, exact, code-like lines on paper are called ____.
Which building block means doing each step in the order it is given? Type one word.
WHY THIS EXERCISESequencing is the simplest building block, and every program uses it.
Try it
Write an algorithm in natural language for filling a watering can and watering one plant.
Hand it to someone and ask them to follow it exactly as written, with no guessing. Where did they get stuck?
On paper, draw Lena's logging routine as a diagram: one box per step, joined by arrows in order.

Great start. Tomorrow you meet variables, the boxes where Beacon keeps its readings.