The increasing efficiency of computers has been widely attributed to powerful algorithms which allow complex tasks to be executed optimally. In this Answer, we'll explore what exactly an algorithm is.
An algorithm is essentially just a defined finite sequence of instructions that, when followed, solve a particular problem and produce a result.
Note: Algorithms have a vast range of complexities.
For example, the following is an algorithm used to find the sum of two numbers:
Take two number inputs.
Add numbers using the + operator.
Display the result.
An algorithm must have a few characteristics to be useful and efficient. These are the following:
An algorithm needs to have 0 or more inputs, and each input's type(s) needs to be known beforehand. An algorithm that doesn't take any input always gives the same output. A simple example of such an algorithm returns the average of 3 and 6; it takes no input and still performs a sequence of instructions/operations to produce a result.
An algorithm needs to produce an output. This output will be the result of the algorithm's instructions, and the output type should be known beforehand.
We saw that an algorithm could have 0 inputs. Is it possible for an algorithm to have 0 outputs as well?
An algorithm must produce a result in a finite number of steps (it must terminate). This is because a sequence of instructions that run infinitely will never produce a tangible output for us to use, thus rendering these steps useless.
An algorithm needs to be independent of any programming language. The steps defined shouldn't depend on a feature of any programming language and must be general enough to be implemented in any language.
All steps in an algorithm need to contribute to the output in some way (an algorithm must be effective). This is because steps that don't influence the result are useless and a waste of computational resources.
An algorithm needs to be definitive and unambiguous. All the steps should be listed clearly in order. This is because mixing up the steps could impact the output in an undesirable manner.
Free Resources