Recursion Flashcards

1
Q

What is Recursion?

A

The process in which a function calls itself directly or indirectly

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the 3 properties of recursion?

A
  1. Performing the same operations multiple times with different inputs.
  2. In every step, we try smaller inputs to make the problem smaller.
  3. Base condition is needed to stop the recursion otherwise infinite loop will occur.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the algorithmic steps for implementing recursion in a function

A

Step1 - Define a base case: Identify the simplest case for which the solution is known or trivial. This is the stopping condition for the recursion, as it prevents the function from infinitely calling itself.

Step2 - Define a recursive case: Define the problem in terms of smaller subproblems. Break the problem down into smaller versions of itself, and call the function recursively to solve each subproblem.

Step3 - Ensure the recursion terminates: Make sure that the recursive function eventually reaches the base case, and does not enter an infinite loop.

step4 - Combine the solutions: Combine the solutions of the subproblems to solve the original problem.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly