Algorithm

A finite set of procedural steps transforming specific inputs to specific outputs.

An algorithm is a finite set of procedural and elementary computational steps to transform a specific set of inputs to a specific set of outputs.

More technically, for a set of inputs II and a set of outputs OO, an algorithm is a function f:IOf : I \rightarrow O where inputs are mapped to outputs.

Algorithms are designed, analyzed and optimized on the theoretical basis of a model of computation and operate within those specifications.

Key Properties

  • Finiteness — must terminate after a finite number of steps
  • Definiteness — each step must be precisely defined
  • Input — zero or more well-defined inputs
  • Output — one or more well-defined outputs
  • Effectiveness — each operation must be basic enough to be done exactly in finite time

Complexity Classes

Algorithm efficiency is measured in terms of time and space as functions of input size nn:

NotationNameExample
O(1)O(1)ConstantArray access
O(logn)O(\log n)LogarithmicBinary search
O(n)O(n)LinearLinear scan
O(nlogn)O(n \log n)LinearithmicMerge sort
O(n2)O(n^2)QuadraticBubble sort
O(2n)O(2^n)ExponentialSubset enumeration