Introduction to algorithms: online searching for girlfriends; Introduction to Algorithms

Source: Internet
Author: User

Introduction to algorithms: online searching for girlfriends; Introduction to Algorithms

Problem:Suppose you need a girlfriend. Your previous search attempts failed, so you decided to find a dating proxy. The dating proxy recommends a girl paper every day. You will interview this person and decide whether to contact her or not. You must pay a small fee to the dating agent for the interview. If you really want to find a girlfriend, you need to spend more money, because you must break up with your current girlfriend and pay a large intermediary fee to the proxy. Your promise is to find the best person at any time to become your girlfriend. Therefore, after interviewing every girl who is invited, if the girl paper is more qualified than her current girlfriend, you will break up with her current girlfriend, and then associate with this new girlfriend. You are willing to pay for this kind of strategy, but want to predict how much it will be.

Now let's consider a deformation of this problem. Assume that we do not want to interview all invited girl papers to find the best one, or keep breaking up with new people because there are always better applicants. We are willing to interact with almost the best invited girl paper, only once. One requirement that we must comply with: after each interview, we must communicate with the invitee immediately or inform the invitee that they will not be able to get this opportunity. How can we strike a balance between minimizing the number of interviews and maximizing the quality of engagement with the invitee?

Answer:

You can use the following method to model this problem. After an invitee is interviewed, we can give him a score; Make score (I) the score given to the I-th invitee, and assume that no two invitees share the same score. After the interview with j invitees, we know which of them has the highest score, but we do not know whether there will be higher scores in the remaining n-j invitees. We decided to adopt this strategy: select a positive integer k <n, and then reject the k invitees before the interview, the first invitee with a higher score than the previous invitee. If the result is the best invitee among the top k interviews, we will contact the nth invitee. This policy is formally represented in the following process ONLINEMAXIMUM (k, n). This process returns the value of the invitee we want to contact.

 

/***** @ Param k the first k rejected invitees * @ param n a total of n invitees * @ return */int ONLINEMAXIMUM (int k, int n) {int [] score = new int [n]; 1int bestscore =-999999; 2for (int I = 1; I <k; I ++) {3if (score [I]> bestscore) {4 bestscore = score [I] ;}} 5for (int I = k + 1; I <n; I ++) {6if (score [I]> bestscore) {7 return I ;}} 8 return n ;}

 

For each possible K value, we hope to determine the probability of the best contacts. Then select the best K value and use this value to implement this policy. Suppose k is fixed first. Set M (j) = maxa <= I <= B {score (I)} to the highest score from a to B. S indicates that we have successfully selected the event of the best invitee, AND Si indicates that the event was successful when the best invitee was the first interview. Because different Si do not intersect, yes. Note that when the best invitee is one of the first k, we will not succeed.

Pr {Si} = 0, I = 1, 2,..., k. So we get

(Formula 2)

Now let's calculate Pr {Si }. To succeed when the I-th invitee is the best, two things must happen. First, the best invitee must be at location I, represented by event Bi. Secondly, the algorithm cannot select any requester in the position k + 1 to the I-1, and this choice only occurs when j satisfies k + 1 <= j <= I-1, the program contains score [j] <bestscore in Row 3. (Because the score is unique, you can ignore the possibility of score [j] = bestscore .) In other words, all score [k + 1] to score [I-1] values must be smaller than M (k); if there is a number greater than M (k, returns the subscript of the first number greater than M (k. With Oi, there are no events selected from the position k + 1 to the I-1. Fortunately, event Bi and Oi are independent. Event Oi depends only on the relative order of values from position 1 to the I-1, while Bi depends only on whether the value of position I is greater than the value of all other positions. The relative order of values from position 1 to I-1 does not affect whether the value of position I is greater than all values from position 1 to I-1, and the value of position I does not affect the order of the position 1 TO THE I-1 value. Therefore, use Formula 1 to obtain

Pr {Si} = Pr {Bi sans Oi} = Pr {Bi} Pr {Oi}

The probability of Pr {Bi} is obviously 1/n, because the maximum value may be any of n positions. If event Oi is to occur, the maximum value from position 1 to the I-1 must be one of the first k locations, and the maximum value may be either of the I-1 locations. So Pr {Oi} = k/(I-1), Pr {Si} = k/(n (I-1 )). Using formula 2

We use credits to approximate the upper and lower bounds of the number. According to Formula 3 of the inequality

The following bounds can be obtained for solving these points:

This provides a very tight circle of Pr {S. Because we want to maximize the probability of success, we mainly focus on how to select k values to maximize the lower bound of Pr {S. (In addition, lower-bound expressions are easier to maximize than upper-bound expressions .) Evaluate the expression (k/n) (lnn-lnk) on k and obtain

So that this derivative is equal to 0, we can see that when lnk = lnn-1 = ln (n/e), or equivalent, when k = n/e, the lower bound of probability is maximized. Therefore, if k = n/e is used to implement our strategy, the probability of at least 1/e can be used to successfully communicate with the most qualified invitee.

 

Formula 1:Pr {A region B }= Pr {A} Pr {B}

Formula 3:When f (k) decreases monotonically, you can use points to calculate the bounds.

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.