| LM | Algorithm |
⚙️ What Is an Algorithm?
An algorithm is a sequence of well-defined, step-by-step instructions used to solve a problem or perform a task.
Algorithms are not limited to computers. We use algorithms in everyday life whenever we follow a set of instructions to achieve a goal.
Example: Baking a Cake
A cooking recipe is a good example of an algorithm. It describes a sequence of actions that must be performed in a specific order.
Example (pseudocode):
Start
Gather all ingredients
Mix flour, sugar, eggs, and butter
IF batter texture is too thick THEN add some milk
Pour batter into a baking pan
Preheat oven to 180°C
Put pan in the oven
Bake for 30 minutes
IF cake is not baked through THEN bake for 10 more minutes
Take cake out of the oven
Let it cool
Serve and enjoy
End
This example contains several important characteristics of an algorithm:
- A clearly defined starting point and ending point.
- A sequence of ordered steps.
- Decisions using conditions (
IF ... THEN). - A clearly defined goal (a finished cake).
Programming algorithms follow the same principles. The only difference is that the instructions are written for a computer instead of a human.