Basis of algorithm: Divide and conquer mode, merge sort θθθθθθ Knowledge Summary

Source: Internet
Author: User


  1. 1. The divide-and-conquer model has three steps at each level of recursion : Decomposition, resolution, merger

  2. 2. Merge sort algorithm fully follows the divide-and-conquer mode :
  3. Decomposition: Decomposition of the sequence of n elements to be sorted into two sub-sequences with N/2 elements
  4. Workaround: Sort two sub-sequences recursively using merge sort
  5. Merge: Merge two sorted sub-sequences to produce sorted answers

  6. 3. Calculate the time required to analyze the divide-and-conquer algorithm:

  7. Suppose that T (N) is the run time of an issue with a scale of N, and if the problem is small enough, such as a constant c,n≦c, then the direct solution requires a constant, and we write it θ (1). Assuming that the original problem is decomposed into a sub-problem, the scale of each sub-problem is the original problem 1/b However, we will see that in many divide-and-conquer algorithms a≠b) in order to solve a sub-problem with a scale of n/b, the time of T (n/b) is needed, so the time N of at (n/b) is required to solve a sub problem, if the decomposition problem becomes sub-problem takes time D (n), the solution of the Jia Cheng original problem of (n) then get the recursive formula:
  8. T (n) ={θ (1) If, n≦c
  9. at (n/b) +d (n) +c (n) Other
  10. 4. Merge sort algorithm
the worst-case run-time t (N) recursion is established to set the number of merge sort n, and an element of the merge sort requires constant time when there are n>1 our elemental decomposition run time is as follows: decomposition: The decomposition step only computes the middle position of the sub-array, which requires constant time, so D (n) =θ (1) Solution: We recursively solve two sub-problems of both scale N/2, which will contribute 2T (N/2) Run time Merging: We have noticed that the process merge requires θ (n) time on a word group with n elements , so C (n) =θ (n) when we add the function d (n) and C (n) to the analysis of the merge sort, we are in it. One theta (n) function is added to another θ (1) function, and the sum is a linear function of N, that is , Θ (n), which is added to 2T (N/2) from the "Resolution" step. , recursion for the worst-case run time t (n) of the merge sort will be given Θ (1) if N=1 T (n) ={2T (N/2) +Θ (n) if n>1 in the 4th chapter, we will see the "Main theorem", which can be used to prove that T (N) is θ (NLGN), where LGN stands for ㏒2n, because the logarithmic function grows slower than any linear function, so the input large enough to run in the worst case is actually θ (NLGN) The merge sort will be better than the insertion sort of the run time Θ (n2) rewrite merge sort algorithm: c if N=1 T (n) ={2T (N/2) +CN if n>1 ( constant C represents the time required to solve a problem of size 1 and the time it takes to process each array element in the decomposition and merge steps )

         LGN + 1 rep layer, CN for each tier contribution total cost  CNLGN + CN=CN ( LGN + 1)   ignoring low order and constant c gives the desired result   Θ (NLGN)                              ,         &NB Sp                          ,         &NB Sp                          ,         &NB Sp                   






Basis of algorithm: Divide and conquer mode, merge sort θθθθθθ Knowledge Summary

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.