Algorithm Examples in CS Thinking
Start with the recap, study the fully worked examples, then use the practice problems to check your understanding of Algorithm.
This page combines explanation, solved examples, and follow-up practice so you can move from recognition to confident problem-solving in CS Thinking.
Concept Recap
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).
A recipe for solving problemsβfollow the steps, get the answer.
Read the full concept explanation βHow to Use These Examples
- Read the first worked example with the solution open so the structure is clear.
- Try the practice problems before revealing each solution.
- Use the related concepts and background knowledge badges if you feel stuck.
What to Focus On
Core idea: An algorithm must be precise, finite, and guaranteed to produce a result for valid inputs.
Common stuck point: Algorithms must work for all valid inputs, not just specific examples.
Sense of Study hint: When designing an algorithm, start by clearly defining the input and the desired output. Then break the solution into small, unambiguous steps that a computer could follow literally. Finally, trace through your steps with a few test inputs to verify correctness.
Common Mistakes to Watch For
Before you work through the examples, skim the mistake guide so you know which shortcuts and sign errors to avoid.
Worked Examples
Example 1
easySolution
- 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
Example 2
mediumPractice Problems
Try these problems on your own first, then open the solution to compare your method.