HiveBrain v1.2.0
Get Started
← Back to all entries
snippetMinor

How to identify Dominant terms in big-O notation and understand Time Complexity of an algorithm?

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
identifytimealgorithmbigdominantnotationunderstandhowandterms

Problem

I understand that Time Complexity is the measure of how an algorithm scales with respect to the input size.

Let us say an algorithm is having a runtime of O($3^n$) + O($n^{20}$)

In order to identify the Non-Dominant term, I followed my intuition for a sample of values:

$3^n$ = {1, 3, 9, 27, ...} for n={0, 1, 2, ...}

$n^{20}$ = {0, 1, 1048576, 3486784401, ...} for n={0, 1, 2, ...}

I see that $n^{20}$ scales up more quickly than $3^n$ for all values of n>=2

Can I say in this regard that the Non-Dominant term is $3^n$?

Solution

No, when we talk about dominant terms in big-O notation we talk about asymptotic domination, i.e. how terms scale as $n \to \infty$. To see this you can think about the limit:
$$\lim_{n \to \infty}\frac{f(n)}{g(n)} = C \ .$$

If this value is $C \in \mathbb{R}$, then we have that $f(n)=O(g(n))$ and so the sum $O(f(n))+O(g(n))=O(g(n))$.

If instead, $C=+\infty$, then it's the opposite, i.e. $g(n)=O(f(n))$ and so the sum will be $O(f(n))+O(g(n))=O(f(n))$.

In your case, even if for small values of $n$ it seems that $n^{20}$ grows faster than $3^n$, this is not the case.

Indeed, $\lim_{n\to \infty} \frac{3^n}{n^{20}} = + \infty $.

You can see it in this way: $3^n=(3^{\log_3 n})^{n/\log_3 n}=n^{n/\log_3 n}$ which grows obviously bigger than $n^{20}$, in particular it surpasses $n^{20}$ as soon as the exponent $\frac{n}{\log_3 n}$ surpasses $20$.

It it worth to notice that asymptotic behavior isn't everything. In practice, polynomials with large exponents or large multiplicative constants can be bigger than exponentials for values of $n$ from real world applications.

Context

StackExchange Computer Science Q#161441, answer score: 2

Revisions (0)

No revisions yet.