Reputation: 9
so I've a algorytmical problem where i need to find the biggest area of a certain type of pixels inside a 2D matrix with following conditions:
Pixel is considered an object with 3 fields:
int x,y;
String type;
boolean visited;
The input file is something like this:
00000000
01100100
00111000
00010000
00000000
Is someone able to tell me if BFS algorithm is a viable solution or should I try a different approach?
Upvotes: 0
Views: 76
Reputation: 5311
BFS would be a better option to go with. More specifically, try a flood fill approach. By making a smart use of visited
variable, make sure that you visit every vertex at-most once, hence keeping the time complexity as minimum as possible.
Upvotes: 1