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