# Computer ScienceAlgorithm Design

Back at the start of this section we defined the term algorithm as a process that achieves a useful outcome. We noted that an algorithm is not written in any specific programming language and may be implemented using different key words and statements depending in which language is chosen to implement the algorithm as a program.

The section on stepwise refinement gave you an example in the following structure table,

0 Do The Weekly Shopping
0.1 Prepare List
0.1.1 Check Cupboards
0.1.2 Check Fridge
0.1.3 Write Down What Is Needed
0.2 Do Shopping
0.2.1 Drive To Shops
0.2.2 Select Items
0.2.3 Pay For Items
0.3 Put Shopping Away
0.3.1 Unpack Shopping
0.3.2 Put Some Items In Fridge
0.3.3 Put Some Items In Cupboards

Having gone through this process, adding detail to each of the vague steps we began with, we can essentially see the terms that are indented furthest as being our algorithm.

We could therefore see our algorithm as being,

Check Cupboards
Check Fridge
Write Down What Is Needed
Drive To Shops
Select Items
Pay For Items
Unpack Shopping
Put Some Items In Fridge
Put Some Items In Cupboards

When we write our instructions in the order in which they should be executed, we are showing an appreciation of sequence. This is the simplest of concepts in algorithm design - the statements are executed in order and, when we design our own algorithms, we must pay attention to the sequence of our instructions.

## Selection

Sometimes our actions will depend on the outcome of a decision (see Decision Tables). We use the term Selection to refer to the parts of our algorithms that depend on the outcome of a decision.

## Iteration

Sometimes an algorithm will require something to be done repeatedly until a condition is met. For example, when we inflate a tyre, we continue to add air until the tyre is fully inflated. Sometimes we repeat statements until a condition is met, sometimes we repeat them while something remains true.

We use the term Iteration or Repetition to refer to those repeating sections of our algorithm.

## Assignment

We use the term assignment for an expression where the left hand side is assigned the value of the right hand side.

For example,

Number ← 5

The left-pointing arrow is a common symbol for assignment.