Using Induction to design use inductive design algorithm [9/14]

Source: Internet
Author: User

Link: http://blog.csdn.net/jj12345jj198999/article/details/6619347

 

 

Recently [Q7] [Title 3]

Problem: a point on the plane can be given to find the distance between the last two points.

The most direct method of induction is to remove a vertex, solve the n-1 vertex problem, and then consider that extra vertex. However, if we only know the minimum distance between n-1 points, the distance from the additional point to the other n-1 points needs to be calculated. In this way, the total number of times of calculating distance becomes n-1 + N-2 +... + 1 = N (n-1)/2. (This is actually an algorithm that compares every two points) We want to find a faster solution.

A grouping Algorithm

The assumption is as follows:

Inductive hypothesis: we already know how to find the shortest distance between any two points in less than N points on the plane.

Now that we can solve the subproblem with less than N points, we can reduce the problem to two subproblems with n/2 points. Assume that N is the power of 2, so that we can divide a set into two equal sets. (We will discuss this assumption later) There are many ways to divide a point set into two equal parts. We are free to choose the best method. We want to obtain as much useful information as possible from solutions to small-scale problems, so we want to maintain as much effectiveness as possible when considering the entire problem. It seems that it makes sense to break down the problem into two unrelated parts with half of each element. After finding the minimum distance between each subset, we only need to care about the distance between the points close to the set boundary. In terms of distance, the simplest way to sort all vertices is to sort them by their X coordinates, split the plane with a vertical line, and divide the integration into two (see figure 4 ). (If there are vertices in the vertical line, we can allocate them to one of the two sets to ensure that the two sets have equal elements) the reason we chose this division is to minimize the effort required to merge the answers. If these two parts overlap in some way, it will make the recent point check more complex. The sorting must be executed only once.

Given a set of P, we break it down into equal subsets P1 and P2 according to the above practice. Then we use the induction method to find the closest two points in each subset. We assume that the shortest distance in P1 is D1, and that in P2 is D2. We further assume that D1 is less than or equal to D2. We need to find the smallest distance in the entire set, that is to say, we need to find whether there is a distance less than D1 between a point in P1 and a point in P2. First, we noticed that it is sufficient to consider the points in the band range with the vertical line in the center of the two parts as the center width of 2d1 (see figure 4 ). Any two points outside the region cannot have a smaller distance than D1. Through the above observations, we can usually exclude many points from consideration, but in the worst case, all points may still be located in this zone, we cannot use direct algorithms for them.

 

 

 

Figure 4: recent questions

 

 

Another less obvious observation point is that for any point P in the band, the distance from a few points on the other side to a point P is smaller than that on d1. The reason is that at least the interval between all vertices on the belt side is d1. suppose P is a vertex in the belt, and its Y coordinate is YP, you only need to consider the coordinate yq on the other side and the | YP-yq | <d1 point is satisfied. Each side of the belt has a maximum of six such points (see Figure 5 in the worst case ). The result is that if we sort all vertices in the band by the Y coordinate of the vertex and scan these vertices in order, we only need to check each vertex and its constant neighbors in order (instead of all n-1 vertices ). The proof of this fact is omitted here (see example [15]).

 

Figure 5: Six vertices separated by D1 in the worst case

 

 

 

Latest algorithm {first attempt}
{P1, p2... PN: Point on the plane}
Begin
Sort the points by the X coordinates of the points {This sorting runs only once at the beginning}
Divide the set into two equal parts
Recursively calculates the smallest distance in each part.
Assign D to the minimum of the two minimum distances.
Exclude vertices out of the split line D range
Sort the remaining points by Y coordinate
Scan these points in Y order and calculate the distance between each point and its five neighbors {In fact, 4 are enough}
If these distances contain then less than D
Update D value
End;

 

 

Complexity: It takes O (nlogn) Time to sort by X coordinate, but this only needs to be executed once. Then we solve the two subproblems with a scale of n/2. Points excluded from the band area can be completed within O (n) time. Next, in the worst case, sorting the remaining points by Y coordinate requires O (nlogn) steps. Finally, we need O (n) Steps to scan the vertex in the band and compare it with the constant neighbor in the sequence. In general, in order to find the nearest pair in n vertices, we are in a subset containing n/2 vertices.
Locate the two closest pairs, and then spend O (nlogn) Time to find the closest pair between the two subsets (plus the time O (nlogn) sorted by X coordinates )). The recursive relationship is as follows:

T (n) = 2 T (n/2) + O (nlogn), T (2) = 1.

The answer to this relationship is T (n) = O (N (logn) ^ 2 ). This is better than a secondary algorithm, but we can do better. Now let's look at the more clever use of induction. [9/14]

 

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.