3 ms·
> Now do breadth-first traversal. With the iterative approach, you just replace the stack with a queue. With the recursive approach, you have to make radical ch
by aleph_minus_one 8mo ago
> Now do breadth-first traversal. With the iterative approach, you just replace the stack with a queue. With the recursive approach, you have to make radical changes.
The reason is that no programming language that is in widespread use has first-class support for co-recursion. In a (fictional) programming language that has this support, this is just a change from a recursive call to a co-recursive call.
- Chinjut 8mo agoHaskell (I realize this may not pass your threshold for widespread use) has equal support for co-recursion as for structural recursion.
- naasking 8mo agoTrue, but couldn't you just simulate it by enqueing a thunk/continuation?
- twic 8mo agoRight, you could use co-recursion. Or you could just use a queue.