Last updated: Thursday 4th
September 2008, 8:57 PT, AHD
Algorithms
An algorithm is a sequence of precise
instructions
(written in English) that leads to the
solution to a problem.
An algorithm can be compared to a
recipe to bake a cake,
a set of directions to enroll for a
class
or a set of instructions to change a
light bulb...
Example Algorithm:
Problem: Find the average of three of numbers
1. Tell the user to
enter the first number
2. Add to a running
total
3. Tell the user to
enter the second number
4. Add to a running
total
5. Tell the user to enter
the third number
6. Add to a running
total
7. Divide the total by
3
8. Print out the
result
The set of eight instructions above
is the algorithm to solve the problem of finding the average of three numbers.
All the instructions necessary to solve the problem are there, and they are
in the correct order.
Computer science
can be defined as the study of algorithms.
An algorithm is a set
of precise instructions to solve a problem.
Algorithms are
used when designing a computer program.
Program Design
problem solving phase
(results in an algorithm)
implementation phase
(results in the program developed from
the algorithm)
Tools for Software Design
Flowcharts are often
used
to graphically
represent algorithms:
A Flowchart:

Pseudocode
Pseudocode is a
more formal verbal way to express an algorithm, designed to be a step closer to
a program written in a high level language like Python:
total
= 0
Display
"Enter number 1"
Input number1
total = total
+ number1
You write an algorithm
first, then convert it into a flowchart or pseudocode, then convert your
flowchart or pseudocode into program (Python) code.
Pseudocode and algorithm example
Documenting a program:
Documents are required
at each stage in the development of
a program:
Requirements Phase
(a document describes what the program has to do)
Design Phase
(a document describes how the program will do it)
Coding Phase
(the document is the program code itself
written in a high level programming language like Python)
Testing Phase
(a document describes the test data and results)
Operation Phase
(the user manual)