If I want to build a graph when the input is a set of points
and an edge exists if the distance between two points is less than
some value x, what is the best way to construct the graph?
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3831 |
3 | Radewoosh | 3646 |
4 | jqdai0815 | 3620 |
4 | Benq | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | gamegame | 3386 |
10 | ksun48 | 3373 |
# | User | Contrib. |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 160 |
5 | -is-this-fft- | 158 |
6 | awoo | 157 |
7 | adamant | 156 |
8 | TheScrasse | 154 |
8 | nor | 154 |
10 | Dominater069 | 153 |
If I want to build a graph when the input is a set of points
and an edge exists if the distance between two points is less than
some value x, what is the best way to construct the graph?
Name |
---|
In the worst case the desired graph will have edges. So you might as well check distance between each pair of points and construct said graph in .
Thanks man! and in the case that I do not want to build the graph, but put each "component" in a subset, Is there a better approach?
One (horrible) idea that comes to mind: put the points into square buckets of side . The points within a bucket are clearly linked together. Compute the convex hull in each bucket. Then find the closest distance between the points of a bucket and those of its 12 relevant neighbors with rotating callipers. Link them if that distance is ≤ x.
There are 20 relevant neighbours, but it is no so important.
Don't quite understand how convex hull will help. IMHO the closest pair may be not from convex hulls.
You are right on both fronts (seems like I can't count). Since convex hull doesn't work, you might have to do something like this, which makes the algorithm even more horrible: https://cs.stackexchange.com/questions/65573/closest-pair-of-points-between-two-sets-in-2d
You could conpute the Delaunay triangulation of the points and then consider only edges which correspont to adjacent faces. This works because the Euclidean MST is known to be a subgraph in this (planar) triangulation graph.