
fill optimizations
I have the following recursive implementation of the fill algorithm:
Code:
void fill(int x, int y)
{
if ( mat[x][y] == 0 )
{
mat[x][y] = 1;
fill(x+1, y);
fill(x1, y);
fill(x, y+1);
fill(x, y1);
}
}
I'm wondering, is this efficient? I read that the recursion doesn't slow things down in this case as much as it does in other algorithms, is this true?
Would an interative approach give a significant increase in speed? Is it worth implementing it iteratively, and if so, how would I approach that?

you don't check bounds
you use global variable (are you sure you need it?)
recursion does not slow things down only if it is optimized by compiler...

> I'm wondering, is this efficient?
No. It uses stupid amounts of stack space for even simple shapes.
Do a web search for "scanline fill algorithm".