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

前端 未结 7 1863
渐次进展
渐次进展 2020-11-29 18:30

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<

7条回答
  •  萌比男神i
    2020-11-29 18:41

    If you limit the problem to lines passing through the origin, you can convert the points to polar coordinates (angle, distance from origin) and sort them by angle. All points with the same angle lie on the same line. O(n logn)

    I don't think there is a faster solution in the general case.

提交回复
热议问题