As a 2D array or grid, where each cell represents a pixel with a specific color.
As a text file containing the names of colors.
As a graph where each pixel is a node connected randomly.
As a single, one-dimensional list of color values.
Target Color
Replacement Color
Seed Color
To count how many times the function has been called.
To define the initial input values for the function.
To provide a condition that stops the recursion and prevents infinite calls.
To perform the main calculation or action of the function.
if
(x, y)
width
height
if (x == 0 || y == 0)
if (x < 0 || x >= width || y < 0 || y >= height)
if (x > width || y > height)
if (x < width && y < height)
The function immediately stops and returns.
It waits for user input before continuing.
The function calls itself for each of the current pixel's valid neighbors.
It checks the diagonal neighbors.
The computer runs out of memory allocated for tracking nested function calls.
A logic error where the algorithm fills outside the intended boundaries.
An error caused by trying to fill an area that is already the replacement color.
True
False
(0, 0)
The bottom-right corner.
The top-left corner.
The center of the image.
It is always faster than the recursive approach.
It avoids the risk of a 'Stack Overflow' error on very large images.
Recursive code is impossible to read or debug.
It uses less memory overall.
The pixel's color is not the target color.
The pixel's coordinates are out of the grid's bounds.
The pixel's color is already the replacement color.
The grid has more than 100 pixels in total.
All done? Get your grade