Rocket holds up the paper tree. "This is great for us, but mission control runs on code."
Raven nods. "Then we write the same steps in pseudocode first. Plain words, code shape."
She writes IF at the start of a line, then a test, then THEN and a label.
"The flowchart and the pseudocode are the same algorithm," Nova says. "Just two ways of showing it."
Rocket squints at the lines. "So every branch on the paper becomes an IF or an ELSE?"
"Exactly," Raven says. "Let us trace card E through it and see where it goes."
An algorithm is a set of steps for solving a problem.
A flowchart shows the steps as boxes and arrows.
Pseudocode shows the same steps as lines of plain, code-like words.
Programmers often plan complex problems both ways before writing real code.
SKY SORTER, VERSION 1
READ brightness, size, streak
IF streak is yes THEN
label = "satellite streak"
ELSE IF size >= 8 THEN
label = "comet"
ELSE IF brightness >= 200 THEN
label = "planet"
ELSE
label = "star"
END IF
WRITE label The sign >= means "is greater than or equal to." So size >= 8 means size 8 or more.
Pseudocode is checked from the top. The first test that is true decides the label.
If we moved the brightness test to the top, bright comets would be labeled planets.
Changing the order of tests can change the answers, even with the same tests.
| Statement | True or false? |
|---|---|
| A flowchart and pseudocode can show the same algorithm. | ? |
| In this pseudocode, the first true test decides the label. | ? |
| Changing the order of the tests can never change a label. | ? |
| Pseudocode must be typed into a computer to be useful. | ? |
Excellent tracing! Tomorrow we look for representations and reasoning in everyday life.