What's the term for “double recursion”?

2019-01-26 05:42发布

Here's an obviously recursive function:

function()
{
    function();
}

We would simply call this "recursive"—but what about this (barely) more complex version?

functionLeft()
{
    functionRight();
}

functionRight()
{
    functionLeft();
}

Is there a term for this scenario, e.g., "double recursion"? Or is there no specific term to distinguish this case from the single-function case above?

3条回答
祖国的老花朵
2楼-- · 2019-01-26 06:01
戒情不戒烟
3楼-- · 2019-01-26 06:05

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

quicksort = quicksort smaller ++ pivot ++ quicksort larger
查看更多
家丑人穷心不美
4楼-- · 2019-01-26 06:19

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.

查看更多
登录 后发表回答