Lesson 1 · Algorithms

🧭 Flowcharts, Pseudocode & Trace Tables

Before writing code, programmers plan algorithms with flowcharts or pseudocode, then test them by hand with a trace table to find mistakes early.

🔷 Flowchart symbols

rounded box start / stop parallelogram input / output rectangle process (a calculation or assignment) diamond decision (yes / no question) arrows the order of steps

Pseudocode describes the same steps in structured English, independent of any one language:

total ← 0 FOR i ← 1 TO 4 INPUT n total ← total + n NEXT i OUTPUT total / 4

🖼️ See it

Flowchart symbolsSymbolMeaningExampleRounded boxstart / stopSTARTParallelograminput / outputINPUT nRectangleprocesstotal ← total + nDiamonddecisionn > 10?
Arrows join the symbols in the order the steps happen.

📋 Trace tables

A trace table has one column per variable (and one for output). Work through the algorithm line by line, writing each new value in a new row.

Only write a value when it changes. This makes it easy to see exactly when and why each variable changed.

🪜 Step by step: tracing a loop

Algorithm:

x ← 1 WHILE x < 20 x ← x * 3 ENDWHILE OUTPUT x
  1. Start: x = 1. Is 1 < 20? Yes.
  2. Loop: x = 3 (3 < 20, yes), x = 9 (9 < 20, yes), x = 27 (27 < 20, no).
  3. Output: 27.
x | output 1 | 3 | 9 | 27 | 27
✏️ Quick check · 1 of 9
Decision

In a flowchart, a decision is drawn as a:

Two exits.
✏️ Quick check · 2 of 9
Input

Input and output use a:

Slanted.
✏️ Quick check · 3 of 9
Pseudocode

Pseudocode is:

Plan.
✏️ Quick check · 4 of 9
Arrow

In pseudocode, total ← total + n means:

← stores.
✏️ Quick check · 5 of 9
Trace

A trace table is used to:

Test by hand.
✏️ Quick check · 6 of 9
Loop

FOR i ← 1 TO 4 runs the loop:

Count.
✍️ Type your answer · 7 of 9

x ← 2 WHILE x < 50 x ← x * 2 ENDWHILE OUTPUT x

x = 2× 2 while x < 502 → 4 → 8 → 16 → 32→ ?

What is output?

Enter an exact answer, without rounding.
Keep doubling.
✍️ Type your answer · 8 of 9

total ← 0 FOR i ← 1 TO 5 total ← total + i NEXT i OUTPUT total

total = 0+1 +2 +3 +4 +5OUTPUT ?

What is output?

Enter an exact answer, without rounding.
Add 1 to 5.
✍️ Type your answer · 9 of 9

count ← 10 REPEAT count ← count − 3 UNTIL count < 0 OUTPUT count

count = 10−3 until count < 010 → 7 → 4 → 1 → ?

What is output?

Enter an exact answer, without rounding.
Subtract 3 until negative.
📝 Lesson quiz · 5 questions
0 / 5
Re-read the lesson, then give it another go.
Question 1 of 5

Which flowchart symbol starts and ends an algorithm?

Question 2 of 5

A process such as total ← total + 1 is drawn as a:

Question 3 of 5

Why use a trace table?

Question 4 of 5

A WHILE loop checks its condition:

Question 5 of 5

A REPEAT…UNTIL loop always runs at least: