Tag Archives: Algoritms

A search algorithm you can act out in primary school

Imagine you’ve got100 children all lined up. You want to know if someone is called Sarah and what position they are.

There’s a few ways you can do this – what you can’t do is ask anyone.

1)Get them in a line. Ask each child their name.

IF Name = Sarah, then check position and say that Sarah is at that position. Keep going until you reach the end.

OR

2) Sort the children into alphabetical order (IMPORTANT)

Find the middle child. IF their name is before Sarah, then get rid of the first half. Or the second half if after Sarah.

Then find the middle child again. Repeat the process as above.

By halving, you will find the Sarah.

This can be adapted into a guessing game.

Imagine a number between 0 – 100. Computer guess 50. If Higher, guesses 75 etc.

Worked example.

Number is 57

Guess 50 (HIGHER) Range left 51 – 100

Guess 75 (LOWER) Range left 51 – 74

Guess 63 (LOWER) Range left 51 – 62

Guess 56 (HIGHER) Range left 57 – 62

Guess 59 (LOWER) Range left  57 – 59

Guess 58 (LOWER) Range left 57 – 57

Guess 57. CORRECT

This is called a DIVIDE and CONQUER algorithm. It’s designed to cut down the work. An alternative could be to go through from 0 – 100 and get the answer HIGHER or LOWER. It would work but it would be slow.

You could do RANDOM guesses.