What's the term for “double recursion”?

后端 未结 3 1282
没有蜡笔的小新
没有蜡笔的小新 2020-12-18 21:54

Here\'s an obviously recursive function:

function()
{
    function();
}

We would simply call this \"recursive\"—but what about this (barely

相关标签:
3条回答
  • 2020-12-18 22:35

    One interpertaion of double recursion could be divide and conquer (e.g) quicksort

    quicksort = quicksort smaller ++ pivot ++ quicksort larger
    
    0 讨论(0)
  • 2020-12-18 22:47

    It's called mutual recursion.

    0 讨论(0)
  • 2020-12-18 22:51

    As Jon Purdy said, the example you gave is called "mutual recursion". The term "double recursion" also exists, but with a different meaning: for when a function uses two recursive calls. The classic example is the Fibonacci function"

    int Fib(int n)
    {
      if (n < 2) return 1;
      return Fib(n-1) + Fib(n-2);
    }
    

    The Fib(n) function recursively calls itself twice.

    0 讨论(0)
提交回复
热议问题