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."
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 writing | Example for Beacon |
|---|---|
| Natural language | Read the water sensor, then show the number on the screen. |
| Diagram | A box that says Read sensor, an arrow, then a box that says Show number. |
| Pseudocode | waterLevel ← INPUT(), then DISPLAY(waterLevel) |
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.
| Statement | True 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. | ? |
Great start. Tomorrow you meet variables, the boxes where Beacon keeps its readings.