Iterative DFS
medium 22 minIterative DFS replaces the hidden call stack with an explicit one.
Where it shows up
The same pattern appears across everyday software.
Garbage collectors
The mark phase of a tracing garbage collector walks every reachable object. Object graphs can be millions deep (long linked lists), so collectors use an explicit mark stack, and some use pointer reversal, a cousin of Morris threading, to mark with almost no extra memory.
Paint bucket tools
Image editors fill a clicked region with a stack or scanline algorithm rather than recursion, because one large region of a 4K image would need millions of nested calls.
File system walkers
Tools like os.walk, find and disk-usage scanners traverse directory trees with an explicit stack or generator, so very deep folder nesting cannot overflow the call stack and the walk can be paused between entries.
Build systems and package managers
Dependency resolvers run DFS with colours to order builds and to report circular dependencies, often iteratively so huge monorepos with long dependency chains do not hit recursion limits.
Compilers and parsers
Abstract syntax trees for machine-generated code can be extremely deep (long chains of a + b + c + ...). Compiler passes use explicit work stacks with enter and exit states to evaluate, type-check and free such trees safely.