You are given an image of a surface photographed by a satellite.The image is a bitmap where water is marked by \'.\' and land is marked by \'*
\'. Adjacent group of
Without any apriori knowledge about the nature of islands the algorithm can not be made more efficient than O(n) in time, however memory-wise your algo can be improved. The visited array is simply redundant. Here is a quick attempt (pardon the usage of ASCII artihmetics - not so readable, but quicker to code)
#include
#define COLS 12
int main()
{
char map[][COLS] = {
"*..........",
"**........*",
"...........",
"...*.......",
"*........*.",
"..........*"
};
int rows = sizeof(map)/sizeof(map[0]);
int i, j;
int main_count = 0;
if(map[0][0] == '*') {
main_count++;
}
for(j=0; j