O: Difference between revisions

From Rosetta Code
Content added Content deleted
(Algoritmic complexity notation)
 
(Added ordered list of notations)
Line 4: Line 4:


Examples: searching in an unordered container of ''n'' elements has the complexity of O(''n''). Binary search in an ordered container with random element access is O(log ''n''). The term random access actually means that the complexity of access is constant, i.e. O(1).
Examples: searching in an unordered container of ''n'' elements has the complexity of O(''n''). Binary search in an ordered container with random element access is O(log ''n''). The term random access actually means that the complexity of access is constant, i.e. O(1).

Here are typical Big-O's listed slowest to fastest (that is, slower algorithms have Big-O's near the top):
*O(n<sup>n</sup>)
*O(n!)
*O(k<sup>n</sup>)
*O(n<sup>3</sup>)
*O(n<sup>2</sup>)
*O(n*log(n)) (fastest possible time for a comparison sort)
*O(n)
*O(log(n))
*O(1)


See also [http://en.wikipedia.org/wiki/Big_O_notation Big O notation]
See also [http://en.wikipedia.org/wiki/Big_O_notation Big O notation]

Revision as of 15:02, 18 July 2008

Complexity. In computer science the notation O(P(n)) is used to denote asymptotic behavior of an algorithm, usually its complexity in terms of execution time or memory consumption. Here P is an algebraic function of n, usually polynomial or logarithmic. n describes the size of the problem. The meaning of O(P(n)) is that the complexity grows with n as P(n) does.

The notation can also be used to describe a computational problem. In that case it characterizes the problem's complexity through the best known algorithm that solves it.

Examples: searching in an unordered container of n elements has the complexity of O(n). Binary search in an ordered container with random element access is O(log n). The term random access actually means that the complexity of access is constant, i.e. O(1).

Here are typical Big-O's listed slowest to fastest (that is, slower algorithms have Big-O's near the top):

  • O(nn)
  • O(n!)
  • O(kn)
  • O(n3)
  • O(n2)
  • O(n*log(n)) (fastest possible time for a comparison sort)
  • O(n)
  • O(log(n))
  • O(1)

See also Big O notation