Big O

77 points by cgrinds


valdemar

In the grey box below the bubbleSort it states:

You may see the average case described using the Greek letter “theta”, Θ, instead of the letter O. Big Theta is similar in that you can have Θ(n) and Θ(1) and so on, the only difference is that it is talking about average performance, not worst-case.

This seems to be based on a misconception Θ has nothing to do with average run-time, it describes that the runtime is bounded both upwards and downwards.

O(g(n)) will tell you that the function will at most grow as fast g(n), Θ(g(n)) means that it grows exactly with that speed, it is a stronger statement to make.

For example if we have a simple function to find the smallest element in a array we could say that it was O(n), but that could mean that there maybe exist a function that can do it faster. If we instead say that it is Θ(n) we will say that you cannot do it faster.

Usually if you are talking about average case complexity you still use the normal big-O notation, see for example quick sort which have an average case of O(n log n), but a worst case perforance of O(n^2): https://en.wikipedia.org/wiki/Quicksort