ngoaho91
ngoaho91

Reputation: 133

Find area fill of 1 in a bool matrix

image

i have a bool matrix, i wanna find area(s) that fill of 1(true value). the area represent as polygon(clock wise).

can somebody give me an idea.

Upvotes: 0

Views: 179

Answers (2)

Samy Arous
Samy Arous

Reputation: 6814

The union-find algorithm is an excellent approach to find connected sub-graphs (or regions in this case). It's also a linear complexity algorithm so it's basically as good as BFS :)

http://www.algorithmist.com/index.php/Union_Find

Upvotes: 0

kaitian521
kaitian521

Reputation: 578

You could use BFS search method to solve the problem, or Flood-Fill algorithm to solve the problem

Or so you can use DFS to solve this problem if you like to use recurve

Upvotes: 1

Related Questions