I have the following recursive implementation of the fill algorithm:
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?Code:void fill(int x, int y) { if ( mat[x][y] == 0 ) { mat[x][y] = 1; fill(x+1, y); fill(x-1, y); fill(x, y+1); fill(x, y-1); } }
Would an interative approach give a significant increase in speed? Is it worth implementing it iteratively, and if so, how would I approach that?