Thursday, February 3, 2011

The Big-O Notation

Big-O notation (also known as big Oh notation, big Omicron notation, Landau notation, Bachmann–Landau notation, and asymptotic notation) (along with the closely related big-Omega notation, big-Theta notation, and little o notation) describes the limiting behavior of a function when the argument tends towards a particular value or infinity, usually in terms of simpler functions. Big O notation characterizes functions according to their growth rates: different functions with the same growth rate may be represented using the same O notation.
In computer science, it is used in the analysis of algorithm. It used to determine the efficiency of the algorithm. When getting the big-O notation, we can get It’s magnitude of order of run time.

Example:
We have this program fragment
for(int x=0;x<n;x++)
{
statement;
for(int y=0;y<n;y++)
{
statement2;
}
}

The statement in inner loop will iterate n*n times
The statement in outer loop will iterate n times.
So, the number of step f(x) = n^2+n.

Now, we want to know the how many steps are there in the fragment. Here, we have n^2+n, where n is the number of input. So, we have f(x)=n^2+n. Basing in the formal definition(although it is not used directly) we can come up with the O notation for f(x). In analyzing algorithm, we commonly derive the O notation of f(x) by following this simplification rules.
-If f(x) is a sum of several terms, the one with the largest growth rate is kept, and all others omitted.
-If f(x) is a product of several factors, any constants (terms in the product that do not depend on x) are omitted.
So, for f(x), the O notation for f(x) is O(n^2). In other words, f(x)=O(n^2) or f(x)” has an order of” n^2.
That’s all folks. Hope you understand. Just comment for some questions.

Source:
http://en.wikipedia.org/wiki/Big_o_notation

No comments:

Post a Comment