Data Structures and Algorithms abbreviated - divide and conquer algorithm

Divide and conquer algorithm (divide and conquer)


 

ALGORITHM

  • The core idea : divide and rule , the original problem is divided into n smaller scale and structure similar to the original question of sub-problems recursively solve these sub-problems, and then merge as a result, we get the solution of the original problem.
  • Suitable for use recursion to achieve .
  • Partition recursive algorithm, each layer will be directed to three recursive operation:
    • Decomposition : the original problem into a series of sub-problems;
    • Solve : recursively solving each sub-problem, if the child is small enough problem, the direct solver;
    • Merge : The results of sub-problems combined into the original problem.
  • Divide and conquer algorithm can solve the problem, generally it needs to meet the following conditions:
    • And the original problem is decomposed into a small problem with the same pattern ;
    • The original problem into sub-problems can be solved independently , there is no correlation between the sub-problems, and this is a clear distinction divide and conquer algorithm with dynamic programming;
    • With decomposition termination conditions , i.e., when the question is sufficiently small, it can be solved directly;
    • Sub-problems can be combined into the original problem , but the complexity of the merge operation can not be too high, or would not achieve the effect of reducing the overall complexity of the algorithm.

For example divide and conquer algorithm analysis

  • For Finding (reverse) order of : there are n data expects the data in ascending order, and that the degree of ordering fully ordered data is n (n-1) / 2 , equal to 0 in reverse order; rather, the reverse order degree of ordering of the data is 0, is the reverse of n (n-1) / 2 . In addition to these two extremes, we calculate the number of ordered pairs or in reverse order, or reverse order to indicate the degree of ordering of the data. How to program the number of ordered pairs obtained a set of data on the number or reverse it?
    • Apply idea to find an array partition A number of reverse order. We can be divided into front and rear halves of the array A1 and A2, A1 and A2 are calculated in reverse order of the number of K1 and K2, and then calculate the reverse between A1 and A2 of the number of K3. A reverse order of that array is equal to the number K1 + K2 + K3.

Guess you like

Origin www.cnblogs.com/wod-Y/p/12098113.html
Recommended