Monday, August 8, 2011

SELECTION AND REPETITION

Algorithms are composed of three basic structures- This includes, Sequence, Selection and Repetition. Algorithms' process of making decisions are called Selections.

Examples-

MOVING THROUGH A SET OF TRAFFIC LIGHTS
If stoplight is green, continue driving.
If stoplight is yellow, while approching slow down to stop.
If stoplight is red, when approaching stop.

DECIDING WHETHER TO TAKE AN UMBRELLA TO SCHOOL
If it is raining outdoors, take the umbrella
If it is sunny and not raining, dont take an umbrella

GIVING A STUDENT AND 'A', 'B', 'C' ON THEIR TEST
If student receives 95% or above, result is an A
If student receives 75% or above, result is a B
If student receives below 75%, result is a C.

When an algorithm rewuires you to repeat a task in order to solve the problem, this is called "REPETITION"

EXAMPLES-

ADDING THE CORRECT AMOUNT OF CORDIAL TO MAKE A DRINK
  1. Fill a jug with 1/4 of a cordial mix.
  2. Fill the jug with 3/4 of water.
  3. Repeat steps 1 & 2 to make the appropriate amount of cordial.
FILLING A BUCKET WITH WATER
  1. Fill a jug with water from a tap.
  2. Pour the water into the bucket.
  3. Repeat steps 1 & 2 until bucket is full to your choice.
BLOWING UP A BALLOON
  1. Use a pump and put the opening of the balloon with the nozzle of the pump.
  2. Push the pump up and down.
  3. When filled with air, of your choise tie the opening of the balloon.
  4. Repeat steps 1 -3 with some more balloons.

No comments:

Post a Comment