http://www.glassdoor.com/Interview/Google-Interview-RVW2382108.htm
I have tried to come with a solution to this problem. But I have not been successful.. Can any one please give me a hint as to how to proceed with this problem.
I will take 2 pair of two points each. That is, I will make 2 chords. Find out their perpendicular bisector. Using those bisectors, I will find out the center of the circle...
Moreover, I will come up with the equation of the circle. And find the point of intersection of the point M with the circle... That should be closest point. However, that point may or may not exist in the set of N points
Thanks.
Assuming that the points on the circumference of the circle are "in-order" (i.e. sorted by angle about the circle's center) you could use an angle-based binary search, which should achieve the O(log(n))
bounds.
A
from the point M
to the center of the circle - O(1)
.I
on the circumference with largest angle less than A
- O(log(n))
.M
is either I
or I+1
. Calculate distance to both and take the minimum - O(1)
. To find a point closest to M, we need to do binary elimination of points based on planar cuts. A little pre-processing of the input points is needed after which we can find a point closest to any given point M in O(lgn) time.
Note that simple binary search of a point closest to M will not work here, e.g.,
To perform the search operation using planar cuts,
In case the data is skewed and not uniformly spread in the circle, we can optimize our planar cuts such that each cut passes through the median (based on angle) of those points which are left in the search operation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With