In summary, we can define an algorithm as a set of instructions or rules defined, ordered and finite that allows solve a problem. In reality, the human being performs algorithms daily. But it happens, that being routine actions, our brain performs them automatically, almost without us being aware of them.
An example of this is, when in the morning we get up and prepare for breakfast. We do it automatically, but certain “instructions” are occurring in our brain that cause our body to move to perform these actions:
- We open our eyes
- We get out of bed
- We put on sandals or house shoes.
- We go to the bathroom
- We brush our teeth
- We take a shower
- We get dressed
- We go to the kitchen
- We prepare breakfast.
In the same way it happens with a computer system. In this case, since the machines at this moment do not think for themselves, we will be their brain. We, through a programming language, will give her instructions, step by step and in a logical way, of what we want her to do. These instructions are what we call algorithm.
For example, if we want an algorithm that allows us to know if a number is even or odd, we can create this flow diagram where we can visualize it. We will always have a beginning and an end.
This algorithm will be written in a programming language using a code editing tool. The code undergoes a series of transformations to finally get the program that will be executed on a computer.
In the execution it is necessary that the program is stored in the internal and volatile memory of the computer, so the processor will read each order of the program, solving it and executing it.
If necessary, internal memory is accessed to manipulate variables, input, output, or storage peripherals. Then, it does the necessary calculations and solves the logical expressions, until the last instruction completes successfully or an error occurs.
What the system returns to us, in the case of n being the number 6, is that 6 is an even number.
In conclusion, algorithms allow us to think logically about the order in which our programs will be developed and executed to obtain the best results and solve problems optimally.