Big Oh notation (written with a
is true if:
there exists constantsand such that for all
It represents the upper bound for a function, and corresponds to the Worst Case running time.
Big-O can be thought of as a
Since
is order , or :
Then it is, at most, roughly proportional to.
Or:
Since
is order , or :
Then it is, at most, roughly proportional to
More Examples:
Lets consider a simple algorithm to fill an array with
Algorithm 1
// Code Cost
arr[0] = 0; c1
arr[1] = 0; c1
arr[2] = 0; c1
...
arr[N-1] = 0; c1
Notice we have the same cost (
Algorithm 2
This algorithm does the exact same thing using a for
loop:
// Code Cost
for (i = 0; i < N; i++) c2
arr[i] = 0; c1
Both algorithms consist of a constant (
For the Set of functions
there exists constants
such that
for all
We write
Convention: A set in a formula represents an anonymous function in the set
Show that