Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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))
           )


And since a tree is a graph, you can just use adjacency matrix and two loops. :)

O(n^2) but very simple.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: