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 | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 151 |
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.