In a plane, n points are given i.e. the input is (x1,y1), (x2,y2)... (xn,yn). Given these n points. Find the maximum number of collinear points.
I think this is O(n^2):
* Create an object for each pair of points
* Sort by slope
* For each group with the same slope, find the lower-left point that occurs most frequently
* Find the max count above across all groups
Note sort by sloe is not nlogn, but n^2logn^2
Use hashtable you can reduce this to n^2
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment