Recursion Flashcards

1
Q

Recursion

What are the 2 types of cases that all recursive algorithms must have?

A
  1. Base case (return)
  2. Recursive case (call the function again)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

When are recursive algorithms useful?

A

When dealing with data structures that have unknown dephs (e.g. searching through a binary tree or file system)

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

What is a factorial and what is it used for?

A

Factorials determine the number of possible combinations (permutations) of n

More specifically, a factorial of n is the product of all positive integers less than or equal to n. However, it is important to remember the factorial of 0 is 1 and not 0. This is because the possible combinations of 0 is no combination which counts as a combination itself

if n = 0, n! = 1

if n >= 1, n! = n * (n-1)!
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

True or False

Any iterative algorithm can be written recursively

A

True

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

Code a function that computes a fibonacci sequence recursively

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