API and software flows
Algorithm flowcharts and pseudocode
An algorithm flowchart represents a program’s logic with three building blocks: sequence (steps one after another), selection (a decision) and iteration (a loop). Each maps directly to pseudocode and code, which is why flowcharts are used to design and teach algorithms.
Three building blocks
Any algorithm can be built from three control structures, a result known in computer science as the structured programming theorem (Böhm and Jacopini, 1966):
- Sequence: steps executed one after another (rectangles connected by arrows).
- Selection: a condition chooses between paths (a diamond, like an
if/else). - Iteration: steps repeated while a condition holds (a decision with an arrow going back, like a
whileloop).
The general rules for diamonds and loops are in decisions and loops.
Symbols used in algorithms
Algorithm flowcharts use the standard symbols, with two that matter more than in business processes:
- the parallelogram for input and output ("Read n", "Display result"),
- the predefined process for calling a function described elsewhere.
Example: find the largest number in a list
- Start.
- Input: list L of n numbers.
- Set max to L[1], i to 2.
- Decision: i ≤ n? If No, go to step 7.
- Decision: L[i] > max? If Yes, set max to L[i].
- Set i to i + 1, go back to step 4.
- Output: max. End.
The same logic in pseudocode:
max ← L[1]
for i from 2 to n
if L[i] > max then max ← L[i]
display maxThe loop in the flowchart (steps 4 to 6) is the for in pseudocode; the inner diamond is the if.
From flowchart to code and back
- Before coding: draw the flowchart to agree on the logic, especially edge cases (empty list, equal values).
- While teaching: students trace values through the chart step by step.
- After coding: draw the chart from the code to explain it or to spot unreachable branches.
Writing it as text
For documentation, the same chart can be kept as Mermaid code next to the source. You can also describe the algorithm in words ("Read a list of numbers. Keep the largest seen so far…") and let an AI generator draft the chart; check the loop exit carefully, as recommended in checking AI flowcharts.
Algorithm or process?
Algorithm flowcharts deal with variables and computations; business flowcharts deal with people and responsibilities. The types of flowcharts overview compares them.