N points are given as input.
Let’s say (x1,y1), (x2,y2)... (xn,yn).
Is there a non-combinatorial solution to find the maximum number of collinear points? Can they be arranged in a fancy data structure that would help this computation?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For each point i, find the slope to every other point j and
look for duplicates. Duplicates can be found by sorting the slopes and
comparing adjacent values. Point i is collinear with the points in
each set of duplicates. Keep track of the maximal set as you go.
For each i, you have n-1 slopes to calculate and sort and compare.
Therefore, using a (n log n) sorting, the complexity of the algorithm is
O(n^2 log n).