You can think of the grid as a (possibly disconnected) undirected
graphs where each filled grid square is a vertex connected by edges to
its neighboring filled squares.  Then the algorithm is a depth-first
search.  This is obviously O(n) where n is the number of _filled_
squares.

Reply via email to