Algorithms
What Is an Algorithm?
An algorithm is a finite, ordered set of steps that turns an input into the output you want, such as sorting a list or finding a route.
Definition
An algorithm is a precise, step-by-step procedure for solving a problem. It takes some input, follows a fixed sequence of instructions, and stops with an output. A recipe is the everyday example; a sorting routine is the programming one.
Programs are built from algorithms. The same algorithm can be written in Python, Java or C, because the algorithm is the logic, not the code.
How it works
A useful algorithm has three properties. It is correct: it gives the right answer for every valid input. It finishes: it never loops forever. It is unambiguous: each step has exactly one meaning.
Algorithms are compared by how their running time and memory grow as the input grows. That growth is written in Big O notation: a linear search is O(n), while binary search is O(log n).