algorithm - Efficiently grouping a list of coordinates points by location in Python -


Given the list of X, Y coordinate points on the 2d grid, what is the most effective algorithm for creating a list of groups is imminent Index number?

For example, a list of two non-adjacent squares (3x3) on the grid (15x15) has been given, the result of this algorithm will be two groups of two equal squared points

I think you can do a flooded algorithm, but it seems to be more than very efficient for a larger 2D array of size 1024.

You can add all coordinate points (for example, using the dictionary structure in Python) and Then for each coordinate point, find the adjacent adjacent adjacent points, find the adjacent neighbors near the point and "merge" them. Also, for each point, you can maintain a pointer to the connected component that is from that point (using the dictionary structure), and for each connected component you create a list of points related to the component.

After that, when you are a neighbor of a point and find a match, then you merge the two connected component sets, which are points for all the new points in the union set and Update. You can show that you only need to hush all the neighbors of all points once and it will find all connected components, and in addition, if you update points for a small portion of the set of two connected components, The number of run-time points will be linear.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -