CS U540 Sample Problems


      (Flood or Seed Fill)

Below is a pseudocode for a recursive seed fill.

void SEED_FILL(int x, int y){
	if ((PIXEL_VALUE(x, y) != BoundaryValue)
		 && (PIXEL_VALUE) != FillValue)){
		SET_PIXEL(x, y, FillValue);
		SEED_FILL(x + 1, y);
		SEED_FILL(x - 1, y);
		SEED_FILL(x, y + 1);
		SEED_FILL(x, y - 1);
	}
}
For the region shown below, assume BoundaryValue = black, FillValue = gray and that SEED_FILL(4, 6) has been called.

a. Number the pixels in the order they are set by the SET_PIXEL(x, y, FillValue) call.

b. Show the stack of recursive calls at the time each pixel is set. How deep does the stack get?


Last Updated: May 27, 2004 5:20 p.m. by

Harriet Fell
College of Computer Science, Northeastern University
360 Huntington Avenue #WHV-340,
Boston, MA 02115
Internet: fell@ccs.neu.edu
Phone: (617) 373-2198 / Fax: (617) 373-5121
The URL for this document is: http://www.ccs.neu.edu/home/fell/CSU540/exams/FloodFillProblem.html