Finding islands in a grid? traversing a graph to find smaller disjoint set

  • Thread starter Thread starter farful
  • Start date Start date
  • Tags Tags
    Graph Grid Set
AI Thread Summary
An efficient algorithm to identify "islands" of 1's in an nxn matrix, where border cells are all 1's, can be achieved through a modified pathfinding approach. The suggested method involves using nodal expansion techniques. Start by selecting a source node that is not connected to the border. From this node, expand to adjacent nodes. If these nodes contain 1's and are also not connected to the border, they form an island. It's crucial to mark nodes as explored to avoid revisiting them during the expansion process. Additionally, defining the criteria for what constitutes an island, such as the number of connected 1's, will enhance the algorithm's effectiveness. This approach allows for efficient identification and potential elimination of isolated groups of 1's within the matrix.
farful
Messages
55
Reaction score
1
I'm working in matlab, and looking for help on how to do the following. (answers in any language or pseudocode will be fine)

I have an nxn matrix, with each cell containing a 1 or a 0. The border cells are all 1's.

Is there an efficient algorithm to determine if there are any "islands" of 1's? That is, any 1's not connected to the border.

For example, if my matrix is:

1 1 1 1 1 1
1 0 0 0 1 1
1 0 1 0 0 1
1 0 1 1 0 1
1 0 0 0 0 1
1 1 1 1 1 1

I'd like to be able to identify the island of the three 1's (and eliminate them).

Thanks!
 
Technology news on Phys.org
How about nodal expansion? You can take the expansion part of pathfinder algorithms for 2D grids and modify it a bit. Choose a source node, if this node is connected to the border, then expand to another node, or several nodes. Choose the node which is not connected to the border as the source and expand to other nodes. If those nodes are 1s and not connected to the border, then you have your island (your current source and expanded nodes). Of course you will have to specify how many 1s make an island, and how these 1s relate to your current source node. You should mark explored nodes as already explored, since they cannot be used again. It will help your expansion algorithm.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top