Big-Theta notation
Unlike Big-O notation, which represents only upper bound of the running time for some algorithm, Big-Theta is a tight bound; both upper and lower bound. Tight bound is more precise, but also more difficult to compute.
An example
If the algorithm for the input n
takes 42n^2 + 25n + 4
operations to finish, we say that is O(n^2)
, but is also O(n^3)
and O(n^100)
. However, it is Ө(n^2)
and it is not Ө(n^3)
, Ө(n^4)
etc. Algorithm that is Ө(f(n))
is also O(f(n))
, but not vice versa!
Formal mathematical definition
Let f
and g
be two functions defined on some subset of the real numbers. We write f(x) = Ө(g(x))
as x->infinity
if and only if there are positive constants K
and L
and a real number x0
such that holds:
K|g(x)| <= f(x) <= L|g(x)|
for all x >= x0
.
Types of complexity
- Worst case: It is at most this complexity for all possible inputs and generated random numbers (if applicable).
- Average: It is this complexity for the average time of all possible inputs.
- Expected: It is this complexity for the average time of all possible generated random numbers. Practically an algorithm with good expected complexity is as good as the one with good worst case complexity, except for some extreme cases you make it possible for a DOS attack.
- Amortized: If something has the amortized complexity O(f(n)), it means the total time of the first k continuous operations has the non-amortized complexity O(f(n)*k). You can't convert a data structure with amortized time complexity into a persistent data structure in naive ways and hope it will keep its complexity.
Sign up or log in
Save edit as a guest
Join Stack Overflow
We recognize you from another Stack Exchange Network site!
Join and Save Draft