Avinash
Avinash

Reputation: 129

Flood Fill Algorithm - number of Empty Area

So I have been trying to implement the Flood Fill Algorithm using 2D Array. I have had success in filling the Array but I am wondering if there is any way to calculate the number of areas that are left unpainted. Just need an idea on how to do this, not asking for any code snippet.

Input :

Input

Output :

Output

Upvotes: 2

Views: 1000

Answers (2)

Markus Unterwaditzer
Markus Unterwaditzer

Reputation: 8244

i = 0

  1. Pick random unfilled dot, increase i by 1

  2. Flood-fill from there, but in a different color

  3. Repeat until no dots left

i is the amount of groups.

You might want to first create some set of unfilled dots and remove dots in step 1 and 2 to avoid linear scanning through the 2d-array to look for new unfilled dots.

Upvotes: 2

Vikram Bhat
Vikram Bhat

Reputation: 6246

Algorithm:-

  1. Start from unfilled point and do floodfill from that point.

  2. Count all points filled till floodfill ends

  3. the count is u r area for enclosed figure.

Upvotes: 0

Related Questions