Monday, July 25, 2011

Selection and Repition

As we have mentioned in previous lessons Algorithms are composed of three basic structures. Sequence, Selection and Repetition.
We have already looked at sequence (the single steps in the algorithms we did before are sequence) so what are selection and repetition.
Solving a problem often involves making a decision between two or more options. In an algorithm this process of making a decision is called selection.

Describe, in plain english, an algorithm for;

(you may need to research algorithms in google.

Use the word “if” ie If red then ……)
1. Moving through a set of traffic lights.

1. Approach the traffic lights
If lights are red, stop
If lights are green, proceed
If lights are amber, slow down

2. Deciding whether to take an umbrella to school.

1. Approach the umberlla
If it is raining, take an umberella
If it is not raining dont take an umberella

3. Giving a student an A, B or C on their test.

1. Look at the students' marks
If the student receives over 95%, give them an A
If the student receives over 80, give them an B

If the student receives over 60, give them an C


Often an algorithm will often require you to repeat a task in order to solve a problem; when this is done in an algorithm the structure is called repetition.

Describe, in plain english, an algorithm for;
1. Adding the correct amount of cordial to water to make a drink.

1. Fill a quarter of a glass with coridal
2. Fill three-quarters of the glass with water
3. Repeat steps 1 and 2 for more cordial

2. Filling a bucket with water.

1. Get a mug
2. Fill it up with water
3. pour it into the bucket
4. Repeat steps 1, 2, and 3 until the bucket is full

3. Blowing up a balloon.

1. Get a balloon and a balloon pump
2.  Put the mouth of the balloon into the pump nozzle
3. Push the pump in and out
4. Repeat the 3rd step until the balloon is filled with air.


No comments:

Post a Comment