3 ms·
Why would you think enumerating a directory is not magic? Walking a tree / BFS is quite easy to implement iteratively, using a search queue. It's a common exam
by lupire 4y ago
Why would you think enumerating a directory is not magic?
Walking a tree / BFS is quite easy to implement iteratively, using a search queue.
It's a common example for teaching Lisp.
Recursion is most natural in problems like implementing evaluation of an abstract syntax trer:
eval(tree) =
apply(node(tree),
map(eval, leaves(tree))
)
- DeathArrow 4y agoAnd since a tree is a graph, you can just use adjacency matrix and two loops. :) O(n^2) but very simple.