What exactly is log in the algorithm?

Source: Internet
Author: User

Always wondered why the log is often seen in algorithms
See "Data Structure and algorithm analysis Java Language description" (3rd edition) 2.4.3 section today
To find out the reason for the realization of the maximal sub-sequence and the partition algorithm
Looking at the last sentence on page 29th, the following section reads:

Even if n = 2 ^ k, then T (n) = n * (k + 1) = n log n + n = O (n log n)

We can get k = log n according to the above N = 2 ^ k
So substituting the formula to eliminate the variable K:

n * k + n = n log n + N

At this point, only one variable can clearly show the relative growth rate expressed by the formula.
So if there is a similar conditional relationship (e.g. N = 2 ^ k) During the derivation of the formula
You can substitute formulas to eliminate extraneous variables in the form of log (such as log N)

Little Tips

LOG: Base 2
LG: Base 10
LN: base E

What exactly is log in the algorithm?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.