A fast way to find connected component in a 1-NN graph?
问题 First of all, I got a N*N distance matrix, for each point, I calculated its nearest neighbor, so we had a N*2 matrix, It seems like this : 0 -> 1 1 -> 2 2 -> 3 3 -> 2 4 -> 2 5 -> 6 6 -> 7 7 -> 6 8 -> 6 9 -> 8 the second column was the nearest neighbor's index. So this was a special kind of directed graph, with each vertex had and only had one out-degree. Of course, we could first transform the N*2 matrix to a standard graph representation, and perform BFS/DFS to get the connected components.