Maximum collinear points in the plane

N are indicated as input.

Let’s say (x1,y1), (x2,y2)... (xn,yn).

Is there a combinatorial solution for finding the maximum number of collinear points? Can they be organized into a fantastic data structure that would help this calculation?

+5
source share
3 answers

For each point, I find the slope to each other point j and look for duplicates. Duplicates can be found by sorting the slopes and comparing adjacent values. Point I is collinear to points in each set of duplicates. Watch out for the maximum set when you go.

n-1 . , (n log n), O (n ^ 2 log n).

+10

+1

: 1) , C (n, 2) 2) . 3) ( ) 4)

: 1) (n-1) * (n-1), . . Set. , . - : {slope1: [(p1, p2), (p1, p3), (p1, p2), (p4, p5)]} {slope2:....}

2) . , . (p1, p2), (p1, p2), (p4, p5) n-, . : [p1, p2], (p1, p3), , - . , , . , : [p1, p2, p3] [p4, p5] ,

O ((n-1) * (n-1) + n) ~ O (n ^ 2). , Set O (1)

0
source

All Articles