Flood fill Algorithm - how to implement fill() in paint? Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Try it on GfG Practice Flood Fill is a classic algorithm used to change the color of an area in a 2D image where all pixels are connected and have the same initial color. Think of it like the paint bucket tool in graphic design software like MS Paint or Photoshop—when you click on a spot, it automatically fills that area with a new color, but only if the neighboring pixels are of the same original color.The key is that only pixels that are directly connected and share the same color are updated. Anything blocked by a different color won’t be changed, just like how a wall or boundary works in drawing software.In Paint or Photoshop, when you click the paint bucket at a pixel:It looks at the color of that pixel.Then it spreads in all four directions (up, down, left, right) to all connected pixels of the same color.It does not fill diagonally.It stops filling when it hits a pixel of different color or the edge of the image.For the implementation of the Flood Fill algorithm, please refer here. Using BFS for Flood Fill, we start from the clicked pixel, use a queue to visit all 4-directionally connected pixels of the same color, and change them to the new color, stopping at different colors or edges—just like a paint bucket tool.. Comment More info K kartik Follow Improve Article Tags : Graph Matrix Recursion DSA Google computer-graphics +2 More Explore DSA FundamentalsLogic Building Problems 2 min read Analysis of Algorithms 1 min read Data StructuresArray Data Structure 3 min read String in Data Structure 2 min read Hashing in Data Structure 2 min read Linked List Data Structure 2 min read Stack Data Structure 2 min read Queue Data Structure 2 min read Tree Data Structure 2 min read Graph Data Structure 3 min read Trie Data Structure 15+ min read AlgorithmsSearching Algorithms 2 min read Sorting Algorithms 3 min read Introduction to Recursion 14 min read Greedy Algorithms 3 min read Graph Algorithms 3 min read Dynamic Programming or DP 3 min read Bitwise Algorithms 4 min read AdvancedSegment Tree 2 min read Binary Indexed Tree or Fenwick Tree 15 min read Square Root (Sqrt) Decomposition Algorithm 15+ min read Binary Lifting 15+ min read Geometry 2 min read Interview PreparationInterview Corner 3 min read GfG160 3 min read Practice ProblemGeeksforGeeks Practice - Leading Online Coding Platform 6 min read Problem of The Day - Develop the Habit of Coding 5 min read Like