What is an Algorithm
What is an Algorithm
Characteristics of an algorithm
Must have a starting point.
Variables are used to store values that are used in processes.
Must have a finite number of steps.
Each of its steps and their inputs and outputs should be clear and must only
have one meaning.
Each step must flow into the next step.
After the last step the algorithm must come to an end.
3. Determine the best solution – From your evaluation of each solution determine
which one is the best.
4. Develop the algorithm – Take your best solution and create a set of logical, well
defined steps written in everyday language.
6. Test and validate the solution. A Trace Table is used to check the correctness of
the flowchart or pseudocode using carefully selected test data.
How to create an algorithm from a problem statement?
Using the steps in the Problem Solving Process section we can take a problem
statement and create an algorithm.
Example:
Problem Statement: Given the length and breadth of a rectangle, find and show
the area.
Determine the Inputs, Processing, Outputs and Storage from the problem
statement using the keywords.
Inputs: length, breadth
Processing: Area = length x breadth
Outputs: Area
Storage: none
Once we have identified all the IPOS we put them in an IPOS Chart.
Input Processing Output Storage
length Area = length x breadth Area none
breadth
Inputs: sumOfMoney
Processing: 25Cents = sumOfMoney x 4
10Cents = sumOfMoney x 10
Outputs: 25Cents, 10Cents
Storage: none
Once we have identified all the IPOS we put them in an IPOS Chart.
Input Processing Output Storage
sumOfMoney 25Cents = sumOfMoney x 4 25Cents none
10Cents = sumOfMoney x 10 10Cents
Using the Characteristics of an Algorithm section as a guide we create the
algorithm as follows.
Start
Output: “Enter a sum of money in dollars”
Input: sumOfMoney
25Cents = sumOfMoney x 4
10Cents = sumOfMoney x 10
Output: “The number of 25 cents are: “, 25Cents
Output: “The number of 10 cents are: “, 10Cents
End