Course Introduction to Programming
Algorithm
In this lesson, we will learn a little about algorithms; this class will be divided into 4 parts:
- Definition of algorithm
- Features
- Examples
- Algorithms vs. Programs
Definition
An algorithm can be defined as a sequence of simple steps to solve a problem, like a tutorial or a cake recipe.
Features
The three main features of an algorithm are
- Sequence: The steps or instructions have a defined order to be executed, so the order of the steps has great importance in the final result of the algorithm.
- Finite: The algorithm must have a finite number of steps.
- Simple: Who executes the algorithm must be able to execute every step.
Examples of an algorithm:
Here are some examples of real-life algorithms for easier understanding:
- Changing a broken lamp
- Remove the damaged lamp
- Place a new lamp
- Make a chocolate cup
- Place 250ml of milk in a glass
- Place two tablespoons of chocolate
- Mix the ingredients
- Opening a door
- Position yourself in front of the door
- If the door is closed, open it
- Walk through the door
- Close the door
Note that in all cases, there are a finite number of steps. However, these algorithms will only be effective if the person performing these actions knows how to perform all the steps of the algorithm. If someone does not know how to open a door or remove a broken lamp, the algorithm becomes useless.
Also, please note that in algorithm 2, if the person places the milk or chocolate first, the result will be the same. Similarly, in many algorithms, there may be steps that can be performed independently of the order. However, unless you want to bang your head for trying to get through a door which is closed, you should pay a lot of attention to the order of the steps in an algorithm.
Algorithms vs. Programs
Now that you know what an algorithm is, you can define a program as an algorithm made for a computer to run.
Following the principle of who executes the algorithm must be able to execute all the steps, a program is created using the programming languages to write the algorithm that must be run by the computer. This way, it can understand exactly what we want it to do.
Keep your good work and until the next class ๐.