Sunday, November 14, 2010

What is the most efficient algorithm to find a line that goes through most points?

Programmer Question

The problem:



N points are given on a 2-dimensional plane. What is the maximum number of points on the same straight line?



The problem has O(N2) solution: go through each point and find the number of points which have the same dx / dy with relation to the current point. Store dx / dy relations in a hash map for efficiency.



Is there a better solution to this problem than O(N2)?



Find the answer here

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails