Looking back--divide and conquer algorithm

Source: Internet
Author: User

    talking about the algorithm of division and treatment, first of all from the literal meaning of understanding: is to divide a problem into a number of smaller problems of the algorithm. In fact, the meaning of the topic. The basic design idea is to decompose a large problem that is difficult to be solved directly into some of the same small problems in order to conquer, divide and conquer.     Design steps: 1) Decomposition: Decomposition into several sub-problems    2) Solving: Solving sub-problems 3) Merging: The solution of the sub-solution is merged into the original problem.     in the self-examination, we encountered the two-way merge algorithm belongs to a division method. Of course, to learn the algorithm, we must find its core, grasp its core, we also understand how the algorithm is going on. Below we find its core through the two-way merging algorithm.
    Example: Give a column number: 4,2,8,3. The two-way merging algorithm is used to arrange ascending order.
    Solution: 1, combining the first two numbers into a small problem, the latter two merged into a small problem: ((4,2) (8,3) can be ((2,4) (3,8 ))                2. ask for their ascending order separately. Then merge the results together to ask for their ascending order. the key is here: The result of the merge is how to ask in ascending order.                  It is very simple to compare the minimum values of two results, such as 2 and 3, to find the smallest place in the first position 2, in the remaining 3 and the previous group of the second number compared to 4, get the smallest place to the second position 3. Just like what the teacher said: The two stacks of the Order of Poker, first take out the first one to compare, find a minimum, in the second Zhang and the first comparison of the big comparison. Loop until finished.
     Summary: Through the above example, we can find the fundamental idea of the period: two rows of ordered numbers from small to large comparison. The general formula can be written in the following form:
               < Span style= "font-size:14pt" >    if    l[i]<=r[j]    then
               < Span style= "font-size:14pt" >         a[k]=l[i]  ,  i=i+1
               < Span style= "font-size:14pt" >    else
A[K]=R[J] , j=j+1

Looking back--divide and conquer 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.