44 total
By the end of this subtopic, you should be able to:
An algorithm is a method for solving a problem by following a series of clear steps in the correct order. Each step must be defined properly so that someone else, or a computer, can follow it without confusion.
Think of an algorithm like a recipe. A recipe tells you exactly what to do, step by step, to make food. In the same way, an algorithm tells you exactly what to do to solve a problem.
For example, if the problem is to find the area of a rectangle, the algorithm could be:
This is an algorithm because it solves a problem using a sequence of defined steps.
A good algorithm should be:
Before writing a real program, an algorithm is often written in one of three forms:
Structured English is a simple way of describing an algorithm using normal English, but in a logical and ordered form. It is easy for humans to read.
For example:
Structured English is useful in the planning stage because it helps you think through the steps without worrying too much about formal syntax.
Pseudocode is a more formal way of writing an algorithm. It looks a little like programming code, but it is not tied to one programming language.
Pseudocode is useful because it:
For example:
INPUT Number
IF Number MOD 2 = 0 THEN
OUTPUT "Even"
ELSE
OUTPUT "Odd"
ENDIF
A flowchart is a diagram that shows the steps of an algorithm using standard symbols and arrows. It is useful for showing the flow of control visually.
Common flowchart symbols include:
A flowchart is especially helpful when you want to see how an algorithm branches or loops.
Sign in to view full notes