Recursion Flashcards

1
Q

What is a recursive algorithm?

A

A method that calls itself somewhere inside it’s body of code

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

What is the Recursive case in a recursive algorithm?

A

Recursively calls the method with different parameters each time, eventually converging on a base case

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

What is a Base case in a recursive algorithm?

A

Detects a condition or if statement, upon which it provides a final answer

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

What is an example of a recursive data structure?
Explain how it can be recursive, and state the base case and recursive case

A

A linked list

  • When adding to the front of the list, the previous front will become the start of the rest of the list
  • The Base case would be an empty list
  • The Recursive case includes one item, and then the rest of the list
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

A Binary search is a recursive algorithm. What are the base and recursive case(s) of a Binary search?

A
  • Base case: item not found if the list is too small
  • Base case: item found if the middle item is the search term

-Recursive case: Calls the Binary search method using either the left or right half of the list, excluding the middle item

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