Recursion in Java

If a function definition is written in such a way that it is called in its own body, then it is called a recursive function. In executing a program, the computer creates what is called the program stack. The program stack is a stack of frames, each frame corresponds to a method invocation. Infinite recursion occurs when there is no base case. It occurs when the base case is never executed. In recursion, fresh memory is allocated during each recursive call. Due to function call overhead in recursion, the recursion works slower than iteration. An infinite recursion occurs when a recursive function calls itself endlessly. This type of condition occurs when there is either no base case or base case is never executed.

To Access the full content, Please Purchase

  • Q1

    Write one advantage of recursive function.

    Marks:1
    Answer:

    The size of the code is reduced, when we use recursive call.

    View Answer
  • Q2

    Is it possible to have more than one base case?

    Marks:1
    Answer:

    Yes, every recursion function can have one or more base case.

    View Answer
  • Q3

    What is another term given to recursive case?

    Marks:1
    Answer:

    Inductive case is also termed as recursive case.

    View Answer
  • Q4

    What do you mean by the term base case?

    Marks:1
    Answer:

    The base case is a small problem that we know how to solve and it is the case that causes the recursion to end. It is also termed as stopping condition.

    View Answer
  • Q5

    Define the term recursion.

    Marks:1
    Answer:

    Recursion is the process through which a method calls itself.

    View Answer