- An algorithm is a step-by-step procedure for solving a problem or performing a task.
- Algorithms are everywhere in our daily lives:
- Cooking recipes are algorithms for making a dish.
- Navigation apps use algorithms to find the fastest route.
- Social media platforms use algorithms to show content.
- Algorithms are based on a linear set of instructions that lead to the solving of a problem.
Algorithms are not just for computers. They can be used in any situation where a problem needs solving or a task needs completing.
Characteristics of an algorithm
Unambiguous
- An algorithm must be clear and precise. There should be no room for interpretation.
- The algorithm must be direct and explicit and not up to perspective.
Finite
- An algorithm must have a specific finite number of steps that lead to the relevant output.
A recipe with infinite steps would never finish cooking the dish.
Well-defined inputs and outputs
- Inputs are the data or materials the algorithm needs to work with, that are usually given by the user.
- Outputs are the results produced by the algorithm.
A cake recipe takes ingredients as inputs and produces a cake as output.
Feasible
- The algorithm should be practical to execute with the available resources.
- The algorithm should not use more resources than necessary, even when they are available.
- An algorithm that requires infinite memory is not feasible for a computer.
- An algorithm that has a higher execution time should not be used if an alternative algorithm with a lower execution time is available.
Independent
The algorithm should be independent of any specific programming language or platform.
ExampleA sorting algorithm should work the same way whether implemented in Python, Java, or any other language.
Self reviewCan you think of a real-world process that is not an algorithm? Why doesn't it meet the criteria?