Intro to Computer Science / Unit 3: Algorithms and Problem Solving
3.1 What Is an Algorithm?
Notes
An algorithm is a finite, step-by-step set of instructions that solves a problem or completes a task.
- A good algorithm is clear (each step is exact), finite (it ends), and correct (it gives the right result).
- Order matters: swapping steps can change the result.
- Algorithms use three building blocks: sequence (steps in order), selection (choosing with a condition) and iteration (repeating).
- Example: a recipe is an algorithm. "Boil water, add pasta, wait 10 minutes, drain" is a sequence.
Practice
Which is the best definition of an algorithm?
An algorithm is an ordered list of clear steps that ends with a result.
Which building block describes repeating a step until a condition is met?
Iteration means repetition, such as looping.
An algorithm for making a sandwich lists the steps: put on the top slice of bread, spread peanut butter, put on the bottom slice. What is wrong?
The order of steps matters, and these steps would not produce a sandwich.
Ready for more? Take the Unit 3 test.