I need help to solve a geometry problem . Consider a set of points. We note the number of points N.
We note d the euclidienne distance and dmax a value.
Two points p1 and p2 are connected if and only if the distance d(p1,p2)<dmax.
The problem is to create an algorithm that returns a list of the size of connected components.
For example in the figure below the algorithm should return
[3, 2, 4, 1]
I drawed the connections in red but initially we only have the points (here in black). If needed the program should calculate all the connections. figure below
I have two algorithm one iterative and the other recursive. I used a DBScan. But it is not fast enough. Yhe complexity is O(N^2)
I need it to be faster with if possible an O(N) or O(N*log(N)).
I read about DFS but i am not really sure...
Thanks for help