Ad
  • Custom User Avatar

    A recursive version if not optimized at compile time generate extra assemby instruction for creating/destroying a stack context for a function call. The context contains temporary variable, caller arguments, and the return for the instruction pointer. Iterative version keeps the same stack context, no need to manage life cycle of called context, so it's faster cause less instructions to execute.

    A teminal recusion can be easily optimized at compile time can be do by «de-recursivate», i.e. transform a recusive algorithm by an iterative one through the use of its own stack with a fast use of this stack. GCC do that for example.

  • Default User Avatar

    why? Is it not good for performance?

  • Custom User Avatar

    Stop posting solutions in discourse ~~ (2nd time today in the same kata...)

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution