An unambiguous set of steps, which when performed correctly by a processor, will result in a process being carried out in a finite time.
Example of an algorithm explaining how to make a cup of coffee:
1. boil the water
2. place coffee in the cup,
3. place sugar in the cup,
4. add the boiling water,
5. add milk,
6. stir.
For this particular algorithm, actually for all algorithms, steps are written in logical order: sequential order (in the sequence you would complete the step). This is absolutely essential as say for example this sequence is jumbled, and step "6" is done before step "2," then you are stirring nothing but air.
Other examples of algorithms:
Making toast:
1. get bread
2. place slices of bread in toaster
3. turn on toaster
4. wait for bread to toast
5. get bread from toaster
Calling a friend on the phone:
1. look up friend's phone number
2. pick up phone
3. dial the phone number
4. wait for friend to answer
5. talk to friend
No comments:
Post a Comment