Flowchart, Pseudocode & Decomposition
Ways to represent an algorithm
We can write an algorithm in plain steps (as in the previous lesson), but two standard forms are clearer: a flowchart (a picture) and pseudocode (structured English).
Flowchart
- Diagram with standard shapes and arrows
- Easy to see the flow at a glance
- Good for small algorithms
- Hard to change for big programs
Pseudocode
- Text with keywords like IF, WHILE, PRINT
- Close to real code
- Easy to modify
- No standard picture
Flowchart symbols
| Symbol | Name | Used for |
|---|---|---|
| ⬭ Oval (rounded) | Terminator | Start / Stop |
| ▱ Parallelogram | Input / Output | Read input, print output |
| ▭ Rectangle | Process | Calculation or assignment, e.g. sum = a + b |
| ◇ Diamond | Decision | Yes/No question, two exits |
| → Arrow | Flow line | Shows the order of steps |
| ○ Small circle | Connector | Joins parts of a long flowchart |
Flowchart: sequence
Steps run one after another, top to bottom. Example: find the simple interest SI = P × R × T ÷ 100.
Flowchart: selection (if-else)
A diamond chooses one of two paths. Example: print "Pass" if marks ≥ 33, otherwise "Fail".
Flowchart: repetition (loop)
An arrow goes back to an earlier step so the steps repeat while a condition is true. Example: sum of numbers from 1 to N.
n = int(input('Enter N: '))
total = 0
i = 1
while i <= n:
total = total + i
i = i + 1
print('Sum =', total)Pseudocode
Pseudocode ("fake code") describes an algorithm using simple keywords in capital letters — INPUT, COMPUTE, PRINT, IF … THEN … ELSE, WHILE, FOR — with indentation to show blocks.
INPUT marks
IF marks >= 90 THEN
PRINT "Grade A"
ELSE IF marks >= 60 THEN
PRINT "Grade B"
ELSE
PRINT "Grade C"
END IFINPUT N
SET fact = 1
FOR i = 1 TO N
fact = fact * i
END FOR
PRINT factWrite one action per line, indent the body of IF and loops, and do not worry about Python syntax like colons or brackets. Anyone should be able to read it.
Flow of control
The order in which steps run is the flow of control. Every algorithm is made from just three building blocks:
Decomposition
Decomposition means breaking a big problem into smaller parts. Each part is solved separately (often by a different team member) and the parts are then combined. A school result system can be decomposed like this:
📁 result-system/ ├── read_marks # input marks of each student ├── total_and_percent # calculations ├── grade # A1, A2, B1 ... ├── rank # sort students └── print_report_card # output
In Python, each sub-problem becomes a function:
# Decomposition: one big task split into small functions
def read_marks():
return [78, 85, 92, 66, 81] # sample marks
def total_of(marks):
return sum(marks)
def grade_of(percent):
if percent >= 90: return 'A1'
if percent >= 80: return 'A2'
if percent >= 70: return 'B1'
return 'B2'
marks = read_marks()
t = total_of(marks)
p = t / len(marks)
print('Total:', t, '| Percent:', p, '| Grade:', grade_of(p))Summary & practice
- Flowchart symbols: oval (start/stop), parallelogram (I/O), rectangle (process), diamond (decision), arrows (flow).
- Pseudocode uses keywords like INPUT, IF, WHILE, PRINT with indentation.
- Flow of control: sequence, selection, repetition.
- Decomposition splits a big problem into smaller ones.
Draw a flowchart and write pseudocode to (1) print the multiplication table of a number, (2) find whether a number is positive, negative or zero.
Hint: (1) needs a loop from 1 to 10; (2) needs two decisions: N > 0, then N < 0.
