The activity selection problem of greedy algorithm--the thinking of solving the real problem

Source: Internet
Author: User

Refer to "Introduction to Algorithms" Second Edition P222 page)

First, how to turn the real problem into a mathematical problem? The idea of mathematical modeling?

1, problem Description: The existing set of competing activities, how to dispatch can find the largest group of activities (maximum number of activities) so that they are compatible with each other?

2, Problem transformation:

First, sort by monotonically incrementing the end time of the activity. So why do you sort by the end time? This question is left behind to explain.

Next, define the appropriate problem subspace, that is, define the set S (i,j). The problem subspace describes real-life problems, whereas set S (i,j) is a mathematical concept that, in some way, defines a suitable set to transform the solution of a problem subspace into a set solution (that is, to find all the elements in a set that meet a certain condition).

3, so the question is, how do you get the set of definitions to describe real-world problems? ----

A, the elements in S (I,J) are represented as activities compatible with activity a (i), A (j)

b, will be active a (1), A (2) ... a (i), A (i+1) 、...... A (j), A (j+1) ... a (n) a monotonically increasing order by the end time! Each collection element has a feature: a start time and an end time.

This is why you should sort by the end time monotonically, because only then can we successfully model and transform the real problem into a mathematical problem.

When the elements in the defined collection (activity) satisfy these two factors, the sub-problem space (from a (1), A (2) ...) 、...... A (i), A (i+1), A (j), A (j+1) ... a (n) activity is selected to select the Maximum compatible activity collection)

Transformed into

Mathematical set problem (the maximum number of elements in a set S (i,j) that meet start and end times that do not conflict with each other )

4, how to prove that the solution of sub-problem S (i,j) is optimal?

Clip technology is the way to disprove it. Modeled by the nature of the set, it can divide the optimal solution of S (i,j) into the optimal solution of S (i,k) s (k,j)!

5, how to construct the solution of the original problem according to the solution of sub-problem?

Constructs fictitious activities A (0) and a (n+1). So, S (0,n+1) represents the solution of the original problem!

6, the mathematical expression of the solution of the problem

The mathematical expression is shown in the second edition of the introduction to the algorithm P244.

--------------------------------------------------------------------------

Introduction to the algorithm introduces a lot of methods of algorithm analysis: from a real life problems, and then one step to transform into a mathematical problem, and then use some analytical techniques (dynamic programming, greed, randomization, probabilistic analysis, divide and conquer ...) ) to represent them as pseudo-code, and finally you can implement them in a programming language!

The activity selection problem of greedy algorithm--the thinking of solving the real problem

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.