• @[email protected]
    link
    fedilink
    2811 months ago

    Best for what?

    For performance you almost always want an iterative instead of recursive. But performance is not the only constraint.

    Some algorithms are innately recursive. Forcing them into an iterative paradigm usually makes them less readable.

    If you are compelled to make a recursive algorithm iterative, consider using an explicit stack. Then you can keep the structure and side step the issues related to call overhead and stack depth.

    • @[email protected]
      link
      fedilink
      311 months ago

      If you are compelled to make a recursive algorithm iterative, consider using an explicit stack.

      yep, did that once to solve a specific problem, worked fine and if I recall correctly I could do it without making a total mess of my code