Algorithm (ii)--------Divide and conquer law

Source: Internet
Author: User

Conditions for the Division and Treatment of Law:

• The size of the problem can be easily solved by scaling it down.
• The problem can be broken down into the same problem of a larger scale than the following: Recursive thinking should be?
• The problem is separate from each other, that is, there is no public problem between the issues.
• Benefit? The solution to the problem can be combined into the solution of the problem.

Case---Quick line:

(1) process

• Divide (Partition)
– Rearrange the elements in order to get such a partition
• All elements in a position s front? is equal to A[s]
• After position s? All elements are equal to A[s]
Conquer: When a partition is determined, the position of the a[s] is determined, and then the two arrays are recursively divided
combine: Sort in place in-place sort, need to merge

(2) algorithm analysis

Best case: All divisions are divided into equal size two? array

Tbest (n) = 2Tbest (N/2) + O (n), (T (1) = 0)= O (NLOGN)

Worst case: Dividing two of the produced? The array contains n-1 elements and 0 elements (the array to be sorted is ordered!). )

Tworst (n) = Tworst (n-1) + O (n), (T (1) = 0) = O (n2)

Average: Assuming that the probability that the division may appear at any location is 1/n, then the average "?" is the recursive relationship of time t (N):


(3) Select a good division benchmark, production, good division:

Find the Dividing datum (approximate median): "Median median"
1. Divide n elements into N/5 groups, 5 elements per group (except the last? Group may not be 5 elements); O (1)
2. The random sort algorithm sorts the 5 elements in each group and takes out the median of each group, together with N/5. O (N)
3. Recursion to find out the median number of N/5, as the Dividing Datum; T (? N/5?)
divide
– the input to the output array by the approximate median number. Partition; O (n)
Conquer
If k = s, return s//s is divided by position
If P < K < S, recursive selection a[p...s-1] k element
If S < K < R, recursive selection A[S+1...R] K (s-p+1)? element
Combine:?

Board Overlay:

In the 2KX2K chess board, just the same as the other lattice, said the lattice is a special, and said the board is a special board. In the board coverage problem, want to figure 4 different forms of L-shaped cards covering the given special chessboard all except special lattice, and any 2 L-type cards must not overlap.

(1) The problem has a solution----mathematical inductive method

– When N=1 (2x2 chessboard), the problem has a solution;
– Assuming that when n=k (2kx2k chessboard), the problem has a solution;
– Then when N=k+1 (2k+1x2k+1 chessboard), divide the chessboard into 4
2KX2K Chess board, special lattice is located in 4 of the chessboard, the remaining 3 of the Board, special lattice.
– How do you convert these 3 special-grid chess boards into special chessboard?
• ?? An L-type card covering these 3 boards of the meeting place, the original problem converted to 4 n=k when the problem, because n=k when there is a solution, so n=k+1 also have a solution.


• When k=0 (1x1 chessboard), that is, special lattice, the number of cards is 0;
• When K>0,
-Divide: Divides the 2kx2k checkerboard into 4 2k-1x2k-1? chessboard. Special lattice is located in 4 of the more?? In the chess board, the other 3 of the board? Special lattice.
-Before recursion, convert the original question to the same 4-scale one.
- ?? A l-shaped card covering these 3? The rendezvous of the chessboard
-Conquer: Recursion to make this division, straight checkerboard shrink to 1x1.
-Combine:?

Algorithm (ii)--------Divide and conquer law

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.