What is constant factors and low-order term in algorithms?

谁都会走 提交于 2020-05-23 02:53:49

问题


In the following video, there is an explanation of asymptotic analysis: https://class.coursera.org/algo-004/lecture/169

But I can't understand what is "low-order term" and "constant factor" itself? (it is at the 4th minute of the video).

The merge sort is 6n*log2(n)+6n. Why 6n is the low-order term and 6 is constant factor in here? Do these terms have concrete definition?


回答1:


Lower-order term:

"Order" here refers to the order of magnitude.

The concept is easy to understand and explain when dealing with very simple terms such as x or x2. x has order of magnitude 1, since it can be written as x1, and x2 has order 2 - the order of magnitude is equal to the power of the variable in the term. But things get a little more hazy (at least for me) when you complicate things by, for example, adding log. [1]

In somewhat informal terms, f(x) is a lower order than g(x) if f(x) < g(x) as x tends to infinity.

It's easy to see that f(n) = 6n is a lower order than g(n) = 6n*log2(n) by just substituting some really large value for n (the correct approach is to mathematically prove it, but substituting a large value tends to work for simple terms).

The terms are essentially the things separated by plus / minus symbols.

So a lower-order term is just any term which is of a lower order than some other term.

Presumably this is the opposite of the leading-order term, which is the term with the largest order of magnitude.

[1]: I deal with big-O a lot, but it's been a while (high-school?) since I've dealt with the basics of order of magnitude, so apologies if I might have missed or forgotten something regarding that part.

Constant factor:

"Factor" is a term in multiplication. For 6n, 6 and n are factors.

A constant factor is simply anything that doesn't depend on the input parameter(s) (which is n in this case).

Here, regardless of what we make n, 6 will always stay 6, so it's constant.




回答2:


When the function in the big-O has several terms, you can keep the one that grows faster because it "hides" the others sooner or later. And you can multiply by any constant.

O(6.N.Lg(N) + 6.N) is the same as O(6.N.Lg(N)) or O(N.Lg(N)) or O(0.01.N.Lg(N) + 42.sin(N) - 1.745 + 1/N)...

The dominant term is always N.Log(N) (and the basis of the logarithm doesn't matter).




回答3:


Usually, you would be better asking questions related to Coursera courses on the forums where other students can help you workout anything you could not understand by your self.

Let's say we have a polynomial function F(n) = 5n³ + 8n + 3, n³ has the highest exponent therefor 5n³ is the highest order term of the polynomial. All other terms are consequently lower order terms.

Now why they are not relevant. Well, here's the definition of the big O notation

T(n) = O(F(n)) if we can find c and n0 such as for all n >= n0 T(n) <= C.F(n)

  1. We can prove that for any polynomial function F(N) = Cn.N^n + Cn-1.N^(n-1) + ...+ C0 F(N) = O(C.N^n) this proof is given in the video.

  2. We can also prove that for every C and K, C.N^K = O(N^K) (simply take c=C)

  3. Finally we can prove that if F(n) = O(G(n)) and G(n) = O(K(n)) then F(n)=O(K(n)), this property is called transitivity.

  4. We then conclude that every function T(n) = O(F(n)) where F is a polynomial is also O(n^k) where k is the highest exponent of the polynomial F.

For simplicity, we reduce F to its highest order term and we drop the constant factor while keeping the mathematical correctness.



来源:https://stackoverflow.com/questions/22614585/what-is-constant-factors-and-low-order-term-in-algorithms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!