Lesson Title: Understanding
Algorithms
BY NSAICHIA JOSEPH NDIFON
LESSON OBJECTIVES
By the end of this lesson, students should
be able to:
Define an algorithm.
List and explain the characteristics of a
good algorithm.
Represent algorithms using pseudocode
and flowcharts.
Identify and explain the basic control
structures used in algorithms.
DEFINITION OF AN ALGORITHM
An algorithm is a step-by-step
procedure or set of instructions
designed to perform a specific task or
solve a particular problem
Example:
Algorithm to make tea:
Boil water
Put tea leaves in a cup
Pour hot water into the cup
Stir and serve
Algorithm to Add two numbers:
Take first and second number
Add them
Store the result
CHARACTERISTICS OF A GOOD
ALGORITHM
A good algorithm should have the following characteristics:
Characteristic Description
1. Input Should have clearly defined inputs.
2. Output Should produce at least one output.
Each step should be precisely defined
3. Definiteness
(clear and unambiguous).
Should terminate after a finite number
4. Finiteness
of steps.
All operations should be basic enough
5. Efficient to be carried out exactly and in finite
time.
Should be easy to understand and
6. Simplicity
implement.
ALGORITHM REPRESENTATION
Algorithms can be represented in various
ways. The two most common are:
A. Pseudocode
B. Flowchart
Question
What is pseudocode?
A. Pseudocode
A simplified, English-like language used to
describe an algorithm logically without
worrying about syntax
Pseudocode is a simple, English-like
description of the steps in an algorithm.
It does not follow any specific
programming language, but it must be
clear, logical, and structured
Pseudocode uses standard
logic terms such as:
Action Common Pseudocode Keyword
Start START or BEGIN
Input INPUT, READ
Output OUTPUT, PRINT, DISPLAY
Assignment SET, = or ←
Decision IF, THEN, ELSE, ENDIF
Looping FOR, WHILE, REPEAT UNTIL
End STOP, END
Examples of Pseudocode
🧮 Example 1: Add Two Numbers
Start
Input A
Input B
Sum ← A + B
Output Sum
End
Examples of Pseudocode
🧮 Example 2: Subtract Two Numbers
Start
Input A
Input B
Result ← A - B
Output Result
End
Examples of Pseudocode
📏 Example 3: Find the Largest of Two
Numbers
START
INPUT A,
Input B
◦ IF A > B
THEN OUTPUT A, "is greater"
ELSE OUTPUT B, "is greater"
◦ ENDIF
end
Class Exercises
Write pseudocode for the following:
To calculate the area of a rectangle (Area
= Length × Width).
To check whether a student passed
(score ≥ 50).
To find the average of three numbers.
Solution 1:Calculate the Area of a
Rectangle
Start
Input Length
Input Width
Area ← Length × Width
Output Area
End
Solution 2: Check Whether a
Student Passed (score ≥ 50)
START
INPUT Score
IF Score ≥ 50 THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
ENDIF
END
Solution3:Find the Average of Three
Numbers
Method 1 Method 2
START START
INPUT Num1 INPUT Num1
INPUT Num2 INPUT Num2
INPUT Num3 INPUT Num3
Sum ← Num1 + Num2 + Average ← (Num1 + Num2
Num3 + Num3)/ 3
Average ← Sum / 3 OUTPUT Average
OUTPUT Average END
END
B. FLOWCHART
A flowchart is a diagram that represents
an algorithm or a process using standard
symbols.
It visually shows the sequence,
decisions, and loops in a task
Standard Flowchart Symbols
CONTROL STRUCTURES
Control structures are the building
blocks that control the flow of
instructions in an algorithm or program.
TYPES OF CONTROL
STRUCTURES (CONSTRUCT)
There are three basic types of logic, or flow
of control, known as:
Sequence logic, or
sequential flow
Selection logic, or
conditional flow
Iteration logic, or
repetitive flow
Sequential Logic (Sequential
Flow)
This is when steps are followed one after
another, in the order they are written
Sequential logic as the name suggests
follows a serial or sequential flow in
which the flow depends on the series of
instructions given to the computer.
Sequential Logic (Sequential
Flow)
Example
Start
Input A
Input B
Sum = A + B
Display Sum
End
Selection Logic (Conditional
Flow)
This is when a decision is made based on a
condition. It chooses one path out of
two or more. Selection logic statements
include
If then
If else
Case
Selection Logic (Conditional
Flow)
Example
Start
Input Age
If Age >= 18 then
Display "You are an adult"
Else
Display "You are not an adult"
EndIf
End
Examples of selection logic
Examples of selection logic
Determine if a number is even or odd
Start
Input number
If number MOD 2 = 0 then
Display "Even number"
Else
Display "Odd number"
EndIf
End
Examples of selection logic
Determine if a student has pass or fail
Start
Input score
If score >= 50 then
Display "Pass"
Else
Display "Fail"
EndIf
End
Repetition (Looping/Iteration)
Used when you want to repeat steps until a
condition is met
This repeats a set of steps over and over
while a condition is true
Examples of loop structure
While your clothes are dirty → keep
washing.
For each student in class → mark
attendance
Examples of loop structure
Start
Set count = 1
While count <= 3
Display "I love programming"
count = count + 1
EndWhile
End
Examples of loop structure
Start
Set count = 1
While count <= 3
Display "I love programming"
count = count + 1
EndWhile
End