For example i have f(N) = 5N +3 from a program. I want to know what is the big (oh) of this function. we say higher order term O(N).
Is this correct method to find big(oh) of any program by dropping lower orders terms and constants?
If we got O(N) by simply looking on that complexity function 5N+3. then, what is the purpose of this formula F(N) <= C* G(N)?
i got to know that, this formula is just for comparing two functions. my question is,
In this formula, F(N) <= C* G(N), i have F(N) = 5N+3, but what is this upper bound G(N)? Where it comes from? where from will we take it?
i have studied many books, and many posts, but i am still facing confusions.
Yes, most people who have at least some experience with examining time complexities use this method.
To formally prove that you correctly estimated big-oh for certain algorithm. Imagine that you have
F(N) = 5N^2 + 10
and (incorrectly) conclude that the big-oh complexity for this example isO(N)
. By using this formula you can quickly see that this is not true because there does not exist constantC
such that for large values ofN
holds5N^2 + 10 <= C * N
. This would implyC >= 5N + 10/N
, but no matter how large constantC
you choose, there is alwaysN
larger than this constant, so this inequality does not hold.It comes from examining
F(N)
, specifically by finding its highest order term. You should have some math knowledge to estimate which function grows faster than the other, for start check this useful link. There are several classes of complexities - constant, logarithmic, polynomial, exponential.. However, in most cases it is easy to find the highest order term for any function. If you are not sure, you can always plot a graph of a function or formally prove that one function grows faster than the other. For example, ifF(N) = log(N^3) + sqrt(N)
maybe it is not clear at first glance what's the highest order term, but if you calculate or plotlog(N^3)
for N = 1, 10 and 1000 andsqrt(N)
for same values, it is immediately clear thatsqrt(N)
grows faster, so big-oh for this function isO(sqrt(N))
.