If you've ever used the 'paint bucket' tool in a photo editor, you've witnessed a flood fill algorithm in action. Traditionally, this is a recursive process: the program marks a pixel, then calls itself to mark the neighbors, and so on. But there's a hidden danger here. If the area is too large, the computer runs out of memory—a dreaded 'stack overflow.'
Beyond the Recursive Loop
Most developers solve this by using a queue or a stack (BFS or DFS), but a truly "stackless" approach is a different beast entirely. Instead of remembering where it has been via a call stack, a stackless floodfill automaton treats the grid itself as the memory.
By using specific states or markers within the cells, the automaton can determine which direction to move next based solely on its current position and the state of its neighbors. It's less like a modern program and more like a cellular automaton, where the logic is embedded in the movement rules rather than a centralized list of tasks.

Why This Matters
Why bother removing the stack? For high-level software, it might seem like overkill. But in the world of embedded systems—think Micromouse robots navigating mazes or low-power hardware—memory is a luxury.
By eliminating the need for a stack, you remove the risk of crashes on large grids and significantly reduce the RAM overhead. It transforms a memory-heavy recursive search into a deterministic state machine that can churn through a grid with surgical precision, regardless of the area's size.
While we usually rely on high-level abstractions, exploring these unconventional structures reminds us that there are always more efficient ways to traverse a map if we're willing to rethink the fundamentals.
Sources
Media



