Recursion Flashcards
What is a recursive algorithm?
A method that calls itself somewhere inside it’s body of code
What is the Recursive case in a recursive algorithm?
Recursively calls the method with different parameters each time, eventually converging on a base case
What is a Base case in a recursive algorithm?
Detects a condition or if statement, upon which it provides a final answer
What is an example of a recursive data structure?
Explain how it can be recursive, and state the base case and recursive case
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
A Binary search is a recursive algorithm. What are the base and recursive case(s) of a Binary search?
- 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