Base case in a recursive method

后端 未结 4 862
遇见更好的自我
遇见更好的自我 2020-12-05 20:45

A theoretical question here about the base or halting case in a recursive method, what\'s its standards?

I mean, is it normal not to have body in it, just a retu

4条回答
  •  青春惊慌失措
    2020-12-05 21:05

    In some cases, your base case is

    return literal
    

    In some cases, your base case is not simply "return a literal".

    There cannot be a "standard" -- it depends on your function.

    The "Syracuse Function" http://en.wikipedia.org/wiki/Collatz_conjecture for example, doesn't have a trivial base case or a trivial literal value.

    "Do you have different thoughts about it??" Isn't really a sensible question.

    The recursion has to terminate, that's all. A trivial tail recursion may have a "base case" that returns a literal, or it may be a calculation. A more complex recursion may not have a trivial "base case".

提交回复
热议问题