The strategy of divide-and-conquer method in algorithm design

Source: Internet
Author: User

Division: Divide and Conquer, also known as Divide and conquer, is a very useful algorithm design strategy, it is a difficult to solve the large problem scale into some small sub-problems, solve each sub-problem, and then merge the solution of the sub-problem. As a matter of course, there are three steps to design a divide-and-conquer approach:

(1) Divide division, divide the problem scale into K small sub-problem, (General k=2)

(2) Conquer treatment, that is, recursion (recursive) to solve sub-problems

(3) Solution of the problem of combine merging sub-problems

About steps (1) Divide the problem scale general k=2 is a heuristic idea based on the balance sub-problem, it is almost always better than the size of sub-problem.

In the second step to solve the sub-problem we talk about recursion, which is also a basis for a problem scale to what extent can be very convenient to solve? This is the common problem and sub-problem in the idea of recursive design. When the scale of a problem is continuously divided until it becomes an ordinary problem (i.e., recursive base), we can solve the problem in O (1) time. As an example,

1 int sum (int a[],int  N)2{3return  (n <1)? 0: Sum (a,n-1) +a[n-1]; 4 }

Yes, it's a simple array summation, but it contains the recursive thought, and the idea of divide and conquer algorithm.

From the above Code analysis and case analysis, we see the division of the charm of the law, in fact, in the data structure, about the most commonly used in the internal ordering of the two algorithm merge sort and fast sorting, are used in the division of the idea Design, the next blog post I will explain the two algorithms of understanding

The strategy of divide-and-conquer method in algorithm design

Related Article

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.