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