Chapter 2: Algorithms, Pseudocode and Flowcharts
Learn how to plan a program before writing Python code using step-by-step algorithms, beginner-friendly pseudocode, and professional flowchart diagrams.
2.1 Chapter Overview
Before writing a Python program, a programmer must understand the problem clearly and design a solution. Algorithms, pseudocode and flowcharts help students plan the logic of a program before coding.
This chapter teaches learners how to think like programmers. Instead of directly typing code, students will learn how to break a problem into smaller steps, arrange those steps logically, and represent the solution using written instructions and visual diagrams.
2.2 Chapter Objectives
- Understand the meaning and purpose of algorithms.
- Write simple algorithms for beginner programming problems.
- Understand the structure and purpose of pseudocode.
- Create pseudocode using clear, human-readable instructions.
- Identify common flowchart symbols and their functions.
- Design flowcharts for simple programming problems.
- Convert algorithm logic into Python code.
Learning Outcomes
- Explain how algorithms support programming logic.
- Differentiate between algorithm, pseudocode and flowchart.
- Draw simple flowcharts using correct symbols.
- Create step-by-step logic for Python programs.
2.3 What is an Algorithm?
An algorithm is a step-by-step set of instructions used to solve a problem or complete a task. In programming, an algorithm explains what the program should do before the actual code is written.
Real-Life Example: Making Tea
- Start.
- Boil water.
- Add tea powder or tea bag.
- Add sugar and milk if required.
- Stir the tea.
- Serve the tea.
- End.
2.4 Characteristics of a Good Algorithm
Clear
Each step must be easy to understand and not confusing.
Ordered
Steps must be arranged in the correct sequence.
Finite
The algorithm must have a clear ending point.
Effective
Each step must contribute towards solving the problem.
2.5 Algorithm Development Process
Programmers commonly follow a structured process when creating algorithms.
2.6 Input, Process and Output Model
Most beginner programs follow the Input-Process-Output model.
| Component | Meaning | Example |
|---|---|---|
| Input | Data entered into the program. | Student marks |
| Process | Calculation or decision performed by the program. | Check whether marks are greater than or equal to 50 |
| Output | Final result displayed by the program. | Pass or Fail |
2.7 What is Pseudocode?
Pseudocode is a simple way of writing program logic using English-like instructions. It is not a real programming language, so it does not follow strict Python syntax.
Pseudocode helps learners focus on logic before worrying about exact coding rules.
Example: Check Student Result
START
INPUT marks
IF marks >= 50 THEN
DISPLAY "Pass"
ELSE
DISPLAY "Fail"
END IF
END
2.8 Why Pseudocode is Important
- It helps students plan the program before coding.
- It is easier to understand than actual programming syntax.
- It allows programmers to discuss logic with others.
- It reduces mistakes during coding.
- It can be converted into Python, Java, C++ or other programming languages.
2.9 Common Pseudocode Keywords
| Keyword | Purpose | Example |
|---|---|---|
| START | Beginning of the logic. | START |
| INPUT | Accept data from user. | INPUT name |
| PROCESS | Perform calculation or action. | total = marks1 + marks2 |
| IF / ELSE | Make decision. | IF age >= 18 THEN |
| DISPLAY | Show output. | DISPLAY total |
| END | End of the logic. | END |
2.10 What is a Flowchart?
A flowchart is a visual diagram that shows the steps of a program using symbols and arrows. It helps programmers see the flow of logic clearly.
Flowcharts are especially useful for beginners because they make abstract programming logic easier to understand visually.
↓
INPUT DATA
↓
PROCESS
↓
DISPLAY OUTPUT
↓
END
2.11 Common Flowchart Symbols
| Symbol | Name | Purpose |
|---|---|---|
| Oval | Start / End | Shows where the process begins or ends. |
| Parallelogram | Input / Output | Shows data input or output display. |
| Rectangle | Process | Shows calculation or processing step. |
| Diamond | Decision | Shows a condition such as Yes / No or True / False. |
| Arrow | Flow Line | Shows the direction of program flow. |
2.12 Worked Example 1: Add Two Numbers
Problem
Create logic to input two numbers, add them, and display the total.
Algorithm
- Start.
- Input first number.
- Input second number.
- Add both numbers.
- Display total.
- End.
Pseudocode
START INPUT number1 INPUT number2 total = number1 + number2 DISPLAY total END
Python Code
number1 = 10
number2 = 5
total = number1 + number2
print("Total:", total)
Total: 15
2.13 Worked Example 2: Check Pass or Fail
Problem
A student passes if marks are 50 or above. Otherwise, the student fails.
Algorithm
- Start.
- Input student marks.
- If marks are greater than or equal to 50, display Pass.
- Otherwise, display Fail.
- End.
Pseudocode
START
INPUT marks
IF marks >= 50 THEN
DISPLAY "Pass"
ELSE
DISPLAY "Fail"
END IF
END
Python Code
marks = 75
if marks >= 50:
print("Pass")
else:
print("Fail")
Pass
2.14 Worked Example 3: Find the Largest Number
Problem
Compare two numbers and display the larger number.
Pseudocode
START
INPUT number1
INPUT number2
IF number1 > number2 THEN
DISPLAY number1
ELSE
DISPLAY number2
END IF
END
Python Code
number1 = 25
number2 = 40
if number1 > number2:
print("Largest Number:", number1)
else:
print("Largest Number:", number2)
Largest Number: 40
2.15 Flowchart Logic for Pass or Fail
The following text-based flowchart shows how a Pass or Fail decision works.
↓
INPUT MARKS
↓
MARKS ≥ 50?
↙ YES NO ↘
DISPLAY PASS DISPLAY FAIL
↓
END
2.16 Difference Between Algorithm, Pseudocode and Flowchart
| Item | Format | Main Purpose |
|---|---|---|
| Algorithm | Step-by-step instructions | Explains the solution clearly. |
| Pseudocode | English-like programming logic | Prepares logic before coding. |
| Flowchart | Visual diagram using symbols | Shows program flow visually. |
2.17 Common Beginner Mistakes
| Mistake | Problem | Correction |
|---|---|---|
| Skipping planning | Students start coding without understanding the logic. | Write algorithm first. |
| Unclear steps | Instructions are too general or confusing. | Write simple and specific steps. |
| Wrong flowchart symbols | Decision and process symbols are mixed up. | Use diamond for decision and rectangle for process. |
| No ending point | The logic does not clearly stop. | Always include END. |
2.18 Hands-On Practice
Activity 1: Simple Greeting Algorithm
Write an algorithm and pseudocode to input a student name and display a welcome message.
Activity 2: Area of Rectangle
Create an algorithm, pseudocode and Python code to calculate the area of a rectangle.
length = 10
width = 5
area = length * width
print("Area:", area)
Activity 3: Odd or Even Number
Design pseudocode and a flowchart to check whether a number is odd or even.
Mini Project: Student Grade Decision
Create an algorithm, pseudocode, flowchart and Python code for a student grading system. The program should input marks and display Grade A, B, C or Fail.
2.19 Assessment Quiz
Answer the following questions. Correct Answer = +1 Mark Wrong Answer = -0.5 Mark
1. An algorithm is a step-by-step set of instructions used to solve a problem.
2. Pseudocode must follow exact Python syntax.
3. A diamond symbol is normally used for decision making in a flowchart.
4. Flowcharts use arrows to show the direction of program flow.
5. The Input-Process-Output model is useful for planning beginner programs.
Your Score: 0
Practical Assessment Task
Create an algorithm, pseudocode and flowchart for a program that calculates total marks and average marks for three subjects. Then write the equivalent Python code.
2.20 Chapter Summary
In this chapter, learners studied algorithms, pseudocode and flowcharts. Algorithms explain the solution in steps, pseudocode expresses logic in English-like programming form, and flowcharts visually show how a program flows from start to end.