Recursive and Non Recursive Flood Fill
- User
Recursive and Non Recursive Flood Fill
- Assistant
Flood fill is a well-known algorithm used to determine the area connected to a given point in a multi-dimensional array, typically an image. There are two types of flood fill algorithm: recursive and non-recursive.
Recursive Flood Fill: Recursive flood fill algorithm is a type of flood fill algorithm that uses a recursive function to fill a region with a given color. In this algorithm, we start at a specific point with a particular color and fill the region around that point with a new color. The process continues recursively until there are no more adjoining pixels with the original color remaining. This algorithm is simple to implement, but it can easily result in a stack overflow if the recursion depth is too high.
Non-recursive Flood Fill: Non-recursive flood fill algorithm is a type of flood fill algorithm that uses a loop to fill a region with a given color. In this algorithm, we start at a specific point with a particular color. Then we add the points at the edge of that region to a queue. We then use a loop to remove those points from the queue one by one and check their adjacent points to determine if they need to be filled. Finally, we add those points to the queue and repeat the process until there are no more adjoining pixels with the original color remaining. This algorithm is more memory-efficient than the recursive algorithm and is commonly used in modern graphics processing.
- User
- Assistant
] Students per Departments: CS 3 Students IT 3 Students DS 2 Students IS 2 Students