Algorithm CS Thinking Example 1
Follow the full solution, then compare it with the other examples linked below.
Example 1
easyWrite an algorithm (as numbered steps) for making a cup of tea.
Solution
- 1 Step 1: Identify the key actions in order โ boil water, prepare the cup, brew, and serve.
- 2 Step 2: Write clear, unambiguous steps: 1. Fill kettle with water. 2. Boil the kettle. 3. Place tea bag in cup. 4. Pour boiling water into cup. 5. Wait 3 minutes. 6. Remove tea bag. 7. Add milk if desired.
- 3 Step 3: Verify the algorithm is complete (handles start to finish) and each step is precise enough for anyone to follow.
Answer
A 7-step algorithm from filling the kettle to adding milk, with each instruction clear and ordered.
An algorithm is a step-by-step set of instructions to solve a problem or complete a task. Good algorithms are precise, unambiguous, and finite.
About Algorithm
A step-by-step set of instructions for solving a problem or accomplishing a specific task. An algorithm must be precise (every step is unambiguous), finite (it terminates after a bounded number of steps), and effective (each step can actually be carried out).
Learn more about Algorithm โMore Algorithm Examples
Example 2 medium
Here is an algorithm: 1. Set total = 0. 2. For each number in the list [3, 7, 2, 8]: add the number
Example 3 easyWrite an algorithm to find the largest number in a list of three numbers: A, B, C.
Example 4 easyA recipe says, 'Add sugar until it tastes right.' Explain why this is a poor algorithm step and rewr