What is an Algorithm?
By infohub — Nov 26th, 2017
In the tech world, an algorithm is a detailed procedure that informs a computer exactly what users want it to do step-by-step. The computer executes these steps as it is given until it reaches the end goal. Almost every activity performed by a computer, from just opening a folder to browsing the Internet, consist of algorithms.
So, in a way, an algorithm is like a recipe to make a certain meal. You need all the ingredients and follow the exact steps if you want your dish to turn out exactly as it is supposed to be. Only in computer and programming, you call the recipe a “procedure” and you call the ingredients as “inputs”. The prepared dish or the end goal of the procedure is called the “output”.
Difference between algorithm and code
It is important to note that an algorithm is different from a computer code. An algorithm is written in English or any other language the programmer can speak and has a definite start, middle, and end. The first step is aptly labeled “start” and the last step of the algorithm is labeled “end”.
What an algorithm constitutes is easy to understand and definite, as opposed to coding. In an algorithm, only the information required to finish the task by the computer is included, and there is nothing unclear, unnecessary or in computer lingo, “ambiguous”.
An algorithm always ends with a solution, and it always tries to provide the best and most efficient solution that can be thought of. Most times, it is a good idea to number all the steps involved although it’s not necessary. Some programmers choose to use indentation instead of using numbered steps. This is called pseudocode, a semi-programming language that describes the steps involved in an algorithm. Most programmers use numbered steps in a diagram, which is called a flowchart.
For better understanding, here is an example of a simple algorithm where a website asks its visitors for their email addresses. This algorithm can also be presented using a flowchart.
Step 1: Start
Step 2: Create a variable to receive the email address of the visitor
Step 3: Clear the said variable in case it’s not empty
Step 4: Ask the visitor for their email address
Step 5: Store the visitor’s response in the variable
Step 6: Check the stored response to make sure it is a valid email address
Step 7: If it is not valid, go back to Step 3
Step 8: End