3 ms·
This neatly explains why recursive depth-first searches are far easier to implement than recursive breadth-first searches. With BFS you'll need to explicitly p
by yen223 9y ago
This neatly explains why recursive depth-first searches are far easier to implement than recursive breadth-first searches. With BFS you'll need to explicitly pass in a queue to track unvisited nodes, whereas with DFS you already get a stack for free!
- neukoelln 9y agoAnd you will also get a stack overflow for free.
- greghendershott 9y agoIn some languages the "stack" may grow until all memory is exhausted. (Some of those languages also guarantee tail call elimination.)