4 ms·
Loops. A recursive algorithm can be transformed into an iterative looping algorithm that uses a fixed stack of memory. There's probably no change in the algor
by pieceof314 11y ago
Loops. A recursive algorithm can be transformed into an iterative looping algorithm that uses a fixed stack of memory.
There's probably no change in the algorithms. They just use non-recursive versions.
- marcosdumay 11y agoWhat's the gain? If you turn your recursive algorithm into an iterative one with a stack, you are sill subject to all the same problems. They probably don't use trees and quicksort at all.
- deleted 11y ago[deleted]
- ktRolster 11y ago> What's the gain? You can prove that you won't have a stack overflow. You can calculate the maximum depth of the stack at compile time, not runtime.
- dclowd9901 11y agoCan't you also just pass a bit through the recursion that contains its depth, and halt the recursion if that number gets too high?
- ktRolster 11y agoYes, but that depends on making sure you get the programming logic correct, whereas with banning recursion outright, it can be tested automatically.
- marcosdumay 11y agoWell, you can either prove that you won't have a stack overflow at the original program, or you can not guarantee that your new code will run out of stack space. If you can calculate the size of the stack at compile time, you don't need to manually manage it.