Explain the concept of recursion in programming and provide an example of its application.

  • Recursion always leads to infinite loops
  • Recursion is a programming technique where a function calls itself to solve a problem
  • Recursion is inefficient and should be avoided
  • Recursion is used only in mathematical calculations
Recursion in programming is a technique where a function calls itself in order to solve a problem. It is commonly used in scenarios where a problem can be broken down into smaller, similar subproblems. An example of recursion is the factorial function, where the factorial of a non-negative integer n is the product of all positive integers less than or equal to n. Recursion can lead to elegant and concise solutions but must be used carefully to avoid infinite loops.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *