May-19-2020, 09:58 AM
As the title says I'm trying to write a grouping algorithm, although I'm not sure if that is the right term to describe what I need. Here a better explanation: I have a matrix m rows by n columns, each cell contains a value that is either 0 or 1; I need an algorithm that, given a coordinate to a cell of the matrix, if that cell contains a '1' returns a list of the "group" of all the adjacent cells that contains '1' values plus all the adjacent cells to the cells adjacent to the first one and so on (a adjacent cell to another is a cell that i vertically, horizontally or diagonally adjacent).
Example:
Example:
matrix = [ [0, 0, 0, 0, 1], [0, 0, 0, 1, 1], [0, 0, 1, 0, 1], [0, 0, 0, 0, 0], ]In this case, given the cell
coord = (0, 4)returns this list:
group = [(0, 4), (1, 3), (1, 4), (2, 2), (2, 4)]This is the problem, I don't necessarily need an algorithm, a guidance to research about this topic would also be appreciated. Thanks in advance.