An unambiguous set of steps, which when
performed correctly by a processor,
will result in a process being carried out in a finite time.
For
example if you were to explain to someone how to make a cup of coffee you would
be defining an algorithm;
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.
1.
Examine the algorithm above. What two
properties of the algorithm enable
it to correctly describe the solution to the problem of making a cup of coffee?
What is it that makes an algorithm correct?(Hint: what would happen if you swapped
step "6" and step "2"?)
An algorithm is correct if a sequence is followed in chronological order. \
Algorithm for posting letter:
1. Write Letter
2. Put letter in envelope
3. Seal envelope
4. Write desired recipient's address at the front of the envelope
5. Go to post box
6. Put Letter in the post box
Algorithm for making toast:
1. Get bread
2. Put in toaster
3. Wait 2-3 minutes while it toasts
4. Take toast out
5. Put on plate
6. If desired apply any form spread on bread.
Algorithm for calling a friend on the phone.
1. Get phone.
2. Dial the correct number
3. Press green call button
4. Wait 30sec to 2 min for person to pick up
5. If person does not pick up repeat steps 1-4 min.
1. Get bread
2. Put in toaster
3. Wait 2-3 minutes while it toasts
4. Take toast out
5. Put on plate
6. If desired apply any form spread on bread.
Algorithm for calling a friend on the phone.
1. Get phone.
2. Dial the correct number
3. Press green call button
4. Wait 30sec to 2 min for person to pick up
5. If person does not pick up repeat steps 1-4 min.
No comments:
Post a Comment