1/9
Flashcards covering key concepts related to recursion.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What is recursion?
Recursion is a programming technique where a function calls itself during its execution to solve smaller versions of the same problem.
What do we call the simple case that can be solved directly in recursion?
The base case.
When is recursion especially helpful?
Recursion is helpful for problems that break into smaller sub-problems, like sorting or searching through tree structures.
How is recursion different from loops?
Both recursion and loops can accomplish the same tasks, but recursion can make the code easier to write and understand, especially for complex problems.
What is the base case for factorial calculation?
The base case is when n equals 0, which returns 1.
What is the structure of a recursive function call for factorial?
It typically involves a function calling itself with a reduced argument until it reaches the base case.
Describe the binary search recursion process.
Binary search involves repeatedly narrowing down the search area by checking the middle element, making recursive calls on the smaller half of the list.
What is the base case for a binary search?
The base case occurs when the search range is invalid (lo > hi), indicating that the name was not found.
In quick sort, when is the base case reached?
The base case is reached when the length of the list is less than or equal to 1, indicating the list is already sorted.
What are Fibonacci numbers?
A series of numbers where each number is the sum of the two preceding ones, starting with 0 and 1.