7 Algorithm Design and Problem Solving Part 2
7 Algorithm Design and Problem Solving Part 2
Any problem that uses a computer system for its solution needs to be decomposed into
its component parts.
The component parts of any computer system are:
Input – the data used by the system that needs to be entered while the system is
active.
Process – the tasks that need to be performed using the input data and any other
previously stored data.
Output – information that needs to be displayed or printed for the users of the
system.
Storage – data that needs to be stored in files on an appropriate medium for use
in the future.
What is an algorithm?
An algorithm is a sequence of instructions that describe the steps to carry out a
specific task. A programmer writes a program to instruct the computer to do
certain tasks as desired. The computer then follows the steps written in the
program code. Therefore, the programmer first prepares a design/plan of the
program to be written, before actually writing the code.
This plan is actually the algorithm.
Writing an algorithm is the first step to programming. If the algorithm is correct,
the computer will run the program correctly, every time.
So, the purpose of using an algorithm is to increase the reliability, accuracy and
efficiency of obtaining solutions.
There are various methods of presenting solution namely:
1. Structure diagrams
2. Flowchart
3. Pseudocode
Structure Diagrams
Structure diagrams can be used to show top-down design in a diagrammatic form.
Structure diagrams are hierarchical, showing how a computer system solution can
be divided into sub-systems with each level giving a more detailed breakdown.
If necessary, each sub-system can be further divided.
Example 2: Structure Diagram to calculate and output the average of two numbers.
Flowcharts
A flowchart is a visual representation of an algorithm. It illustrates the solution to a
particular problem.
It includes shapes/symbols which describe the individual tasks to be carried to
solve a particular problem.
Flowcharts Symbols:
Example of Flowchart:
The purpose of this flowchart is to calculate the sum of two numbers:
1. Insert first number
2. Insert second number
3. Calculate Sum
4. Output Sum
Pseudocode
It is considered as a non-formal language that helps programmers to write
algorithm.
It is a detailed description of instructions that a computer must follow in a
particular order.
It is intended for human reading and cannot be executed directly by the computer.
Pseudocode is written in a form that can be easily converted into any programming
language statements.
Example 1: Pseudocode that will input two numbers and output the total.
BEGIN
DECLARE Number1, Number2: Integer
INPUT Number1, Number2
Sum= Number1 + Number2
OUTPUT Sum
END
Note: The above program can be easily interpreted by a non-programmer.