Make delicious recipes!

Flood fill algorithm



Problem: Given a 2D integer matrix where each integer corresponds to a color
Write a function to fill 'newColor' in the biggest region containing a given point (x,y)


Solution: Such algorithms fall in the category of flood fill algorithms.
One recursive algorithm can be:
  1. Fill current pixel containing (x,y) with newColor
  2. Check East, West, North and South pixels adjoining current pixels. If their color is oldColor, replace it.
  3. Recurse for the new adjoining pixels






Like us on Facebook to remain in touch
with the latest in technology and tutorials!


Got a thought to share or found a
bug in the code?
We'd love to hear from you:

Name:
Email: (Your email is not shared with anybody)
Comment:

Facebook comments:

Site Owner: Sachin Goyal