Divide and conquer algorithm-nearest point problem finding the closest pair of points

Source: Internet
Author: User

Problem Description:

Input: Point set Q output on space plane: two closest point pairs

Problem simplification: If you are looking for the nearest point pair in a straight line, you can use sorting and then find the nearest nearest point.

Divided treatment ideas:

Divide divides it into two parts q1,q2 T (n) = O (n)

Conquer find nearest point pair <p1,p2>,<q1,q2> T (n) = 2T (N/2)

Merge compare the distance between two points near the point of separation <p3,q3> and find the <p1,p2><q1,q2> distance t (n) = O (n)

Time complexity: T (N) =o (1) n=2

T (n) =2t (N/2) +o (n) =o (NLOGN) n≥3


Two-dimensional space problems:

The divide and conquer phases are similar to one-dimensional problems, with the X=m line divided into two sub-parts to find the nearest point to <p1,p2>,<q1,q2>

D=min{<p1,p2>,<q1,q2>}, the point of the merge stage must be within the [M-d,m+d] range.

There seems to be a lot of optimizations, but the worst case scenario is that the number of points within that range corresponds to a n^2 level of complexity.

More optimized scenario: For a point, there are up to 6 points on one side that are less than D. Specify the following

, the point P (x0,y0) in the left-hand area of the l:x=m, the point at which the distance is less than D is within a circle with a radius of D, at the center of P,

The portion of the circle to the right of the l:x=m must be in (m,y0-d) the lower-left vertex, (m+d,y0+d) within the rectangle of the upper-right vertex, which is within the red rectangular region of the figure.


When the rectangle is divided into 6 blocks, with a length of 2D/3 and a width of D/2, the maximum distance of points within each small rectangle is 5d/6 (diagonal), that is, each small rectangle has a maximum of one point.

Because if there are two points in the same rectangle, the minimum distance will not be d.

Therefore, there is a maximum of 6 points for each vertex in the [M-d,m+d] range to be judged.

Things to keep in mind:

1. To set up a good data structure for easy processing

2. To Preprocess, the point set is sorted by x, Y, respectively, and the two sort sorts are maintained together.

Time complexity: T (N) =o (1) n=2

T (n) =o (n) +2t (N/2) +o (n) =o (NLOGN) n≥3




Divide and conquer algorithm-nearest point problem finding the closest pair of points

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.