Algorithmic note: Divide and conquer

Source: Internet
Author: User

Divide and conquer

1. Break down to the sub-problem of a smaller k.

2. Sub-problems are independent of each other.

3. The merge is the same as the original problem.

Tips: The best sub-scale is roughly the same, making the process easier.

In most cases, the time complexity of the divide-and-conquer method:

1.n=1, T (n) = O (1);

2.n>1, T (n)-KT (n/m) + f (n)

If f (n) = N^l

Then there is t (N):

1.l<logmk,nlogmk

2.l=logmk,nllogn

3.l>logmk,nl

Classic examples of merge sort ~

Code Address: http://www.cnblogs.com/rimochiko/p/7587272.html

Explanation of ideas:

Need additional space to assist, divided into the left and right, take the left and the right to compare, and then put the small one into the newly opened space.

The complexity of the merge algorithm is:

1.n=1, T (n) = O (1);

2.n>1, 2T (N/2) + O (n);

A quick sort of classic example ~

Code Address: http://www.cnblogs.com/rimochiko/p/7587476.html

Explanation of ideas:

Divides the array into three sets, one is less than the area, one is the area equal to the datum, one is greater than the area, and then recursively sorts.

Algorithmic note: Divide and conquer

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.