Recursion Flashcards

1
Q

What is recursion?

A

It is a process, that involves defining a problem in terms of itself.

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

what are the 3 main parts of a recursive algorithm?

A

Base case
Working towards the base case
Recursive cal

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

What are some popular recursive algorithms of recursive algorithms?

A

-> Adding Numbers
-> The Fibonacci sequence
-> Factorial
-> Sodoku games
-> Hanoid towers

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

What are the advantages of recursion?

A

-> It makes code more readable
-> It expresses the natural mathematical aspects of a problem clearly
-> It is suitable for problems that can be broken down into smaller similar problems
-> It solves large problems by breaking them down into smaller ones
-> It can be used for mathematical modeling

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

What are the disadvantages of recursion?

A

-> They consume a lot of memory
-> They cause a stack overflow
-> Sometimes the iterative approach is more efficient than the recursion

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

Differentiate between direct and indirect recursion.

A

Direct recursion is when a function calls itself directly.

While indirect recursion is when a function calls another function that calls the original function

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

What is tail recursion?

A

This recursion in which the recursive call is the last statement executed by the function.

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

Differentiate between recursion and iteration.

A

Acronym: Come To US

Code size: Recursion has a smaller code size than iteration

Termination: Recursion terminates when the base case condition is fulfilled, while iteration terminates when the given condition fails.

Use: Recursion is used for function, iteration is used for loops

Stack memory: every recursive call requires extra stack memory, white iteration does not

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

What are the applications of recursion in real-world problems?

A

-> Tree and graph traversal
-> Sorting Algorithms
-> Divide and conquer algorithms
-> Factorial Generation
-> Memoisation
-> Backtracking algorithms

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