5 ms·
Some algorithms solve a problem by examining solutions to other instances of the same problem. Minimax and quicksort work this way, as do a lot of tree and grap
by prodigal_erik 15y ago
Some algorithms solve a problem by examining solutions to other instances of the same problem. Minimax and quicksort work this way, as do a lot of tree and graph traversal problems. Implementations of these algorithms are inherently recursive, in the sense that you're going to need to say "carry out the whole algorithm again here". You can always fake recursion by creating objects to hold the state of the call graph (or stack, if you don't have continuations), but that's so cumbersome to write or read that you'll quickly be better off in a language that doesn't force you to do it, just as we've now all adopted languages which actually provide functions rather than faking it by saving and restoring variables around GOTOs (I wish I were kidding).