Online algorithm (online algorithm)

Source: Internet
Author: User

See an interesting question. For details, seeHere.

I had a knowledge attitude towards the results of the problem, so I did it. Write down the detailed analysis process here.

Based on our thinking, we first assume that a fixed K value is selected, and then the best probability can be found. Finally, determine how to select the best K value to maximize the probability.

First define several symbols: m (j) indicates the highest score from the first to the J-th person, and s indicates that we have successfully selected the event of the best person, then s I It indicates that the best person is the I event. Obviously different S I Is not intersecting, so P {s} = P {s 1 } + P {s 2 } +... + P {s N }. Note that if we assume that the best person is the K, no one before K will succeed, so P {s I } = 0, I = 1, 2,... K. So P {s} = P {s K + 1 } + P {s K + 2 } +... + P {s N }.

The current job is to calculate P {s I }, I = k + 1 ,..., n, that is to say, I will succeed. In this case, there are two things that must happen: first, the best person must be at location I, if none of the best people is the I, what do you mean? Use event I It indicates that the best person appears on location I. Due to the randomness of the person distribution, it is obvious that I = 1/N. The second thing is that we can't choose the location k + 1 to anyone in the I-1, and this to happen, we have to score these people must be less than m (K ), otherwise, we will select anyone with a score greater than m (k) according to our policy. Order B I Indicates the event in which no one is selected for the person ranked between k + 1 and I-1. So P {s I } = P { I B I }. Let's take a look at the relationship between events a and B. A indicates that the personal I score is the highest, B indicates that from the first to the second I-1 individual's score can not exceed the second person's score, and as to the prior I-1 individual's relative order, there is no impact on B, that is to say the relative order of the first 1 to the I-1 individual if, does not affect the I personal score is greater than 1 to all the values in the I-1, so easy, the two events are independent of each other.

If B event occurs, the maximum value from 1st to the I-1 individual must appear before the K individual, otherwise it will certainly select K to a person in the I-1. And this maximum value can be any number from 1 to I-1, so P {BI} = K/(I-1 ).

Now it can be calculated. Because A and B are independent, then P {sI} = P {IBI} = P {I} * P {BI} = K/(n * (I-1 )).

AfterWhich of the following summation formulas looks familiar? Unfortunately, I forgot too much about advanced mathematics. After a fierce calculation, I found that I could not find it online.Long ago, I remembered that this is a famous harmonic series, which is divergent and cannot be used to calculate its exact value. After a while of being depressed, find a way to use points to seek their upper and lower boundaries. Use the following formula:

Then sum is converted:

The two credits can be obtained by using the formula ln.N-LnK.

The final result is:

Now we know the upper and lower bounds of P {s}, that is, the maximum value and the minimum value. Now we can select the correct K value to make the lower bound take the maximum value.Evaluate the derivative of K to obtain (ln n-ln K-1)/n, so that the derivative is 0 to obtain ln K = ln n-1, that is, K = N/e, E is a natural number, that is, 2. 71828 ......, then K is approximately 0.37n.

From this we can see that onlineAlgorithmOnly the best probability can be obtained. There is no way to select the best value. In fact, life is such an online algorithm. Because you never know what to do next, you can only guess based on the past. Once you go wrong, you will never be able to come back again. "If everything can be done again, I will choose ...... we hope we have made the best choice based on the same online algorithms. The wise man once said, "Don't be afraid before the age of 30, don't regret it after the age of 30." Once you make a decision, don't regret it, because even if you regret it, there is no chance to come back.

PS: Let's talk about the online algorithm and offline algorithm. The offline algorithm knows all the input, the best policy is selected based on certain conditions, while online algorithms cannot predict the subsequent input. They can only make the best decision based on the current situation, online algorithms seek the same good results as offline algorithms. For more information about online algorithms, see Wikipedia . It reminds me of suit's mantra: "A person cannot do anything wrong for a lifetime.

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.