Wednesday 1 September 2010

Intro to Computer Science 3

What is an 'algorithm': a set of instructions to solve a problem STEP BY STEP.

Example of algorithm to solve the problem of frying eggs for one person:

1. Takes two eggs out of the fridge
2 Heat the oil in the pan so that the temp rises enough but not too much
3 Throw the eggs in by breaking them off their shells
4 Let them to fry till they are robust but not burnt
5 When robust remove them from the pan to place them on a plate
6 Close the pan fire


A more complex and correct algorithm is one that expects errors and misses. The following is from wikipedia on algorithms:

1. Get the frying pan.
2. Get the oil.
a. Do you have oil?
1) If yes, put it in the pan.
2) If no, do you want to buy oil?
a) If yes, the go out and buy.
b) If no, you can terminate.
3. Turn on the stove.
(etc)


No comments:

Post a Comment