2. What is an algorithm
• An algorithm is a set of steps which when followed will solve a problem.
• When developing an algorithm the following THREE things must be
considered.
• Defining the problem
• Designing the algorithm
• Testing the algorithm on paper- this will ensure that it works correctly.
3. Defining the Problem
• Say what the problem is about or what it will do.
• The problem should be analyzed and objectives stated.
• Objectives must include the following instructions or steps:
• Specify the input
• Specify the output
• Specify the processing
• Specify storage (in some cases)
4. Designing the Algorithm
• When designing the algorithm remember that it
must:
• follow the rules
• be explicit
• have a start and stop point.
• Can be written in structured English, pseudocode, or a
flow chart.
•
5. Designing the Algorithm cont…
• Algorithm must also be:
• Correct:- provide input, output and processing instructions
• Simple:- steps performed in logical order
• Clear:- easy to read
• Precise:-present solution without referring to programming codes.
• Easy to implement:- easily transferred to programming codes
• Efficient:-enable codes to produce results quickly
6. Types of Algorithm
• Narrative: uses English like statements
when listing the steps
• Example: Find the average of three
numbers.
1. Get first number
2. Save as num1
3. Get second number
4. Save as num2
5. Get third number
6. Save as num3
7. Add the three numbers
8. Save result as sum
9. Divide sum by 3
10. Save result as average
11. Display the average
7. Pseudocode Algorithm
• This type of algorithm is written using codes that are similar to the codes that are
used in a programming language.
Example:
• Find the average of three numbers.
• Read num1,num2,num3
• Sum=num1+num2+num3
• Average=sum/3
• Print Average
8. Flow Chart
• This type of algorithm uses a diagram or pictorial representation of the steps
in solving the problem.
• Example:
Find the average of three
numbers average=Sum/3
Start
Num1, num2, num3,
average
Stop
Sum=num1+num2
+num3