Recall & Review
beginner
What is recursion in the context of arrays and strings?
Recursion is a method where a function calls itself to solve smaller parts of a problem, like processing elements of an array or characters of a string one by one until a base case is reached.
Click to reveal answer
beginner
What is the base case in a recursive function working on an array?
The base case is the condition that stops the recursion, often when the array index reaches the end or when the size of the array segment to process is zero.
Click to reveal answer
intermediate
How does recursion help in reversing a string?
Recursion reverses a string by swapping characters from the start and end, then calling itself on the smaller substring inside, until the base case of one or zero characters is reached.
Click to reveal answer
beginner
Explain how to find the sum of elements in an array using recursion.
To find the sum recursively, add the first element to the sum of the rest of the array found by a recursive call, stopping when the array is empty (base case).
Click to reveal answer
beginner
What happens if a recursive function on arrays or strings does not have a proper base case?
Without a proper base case, the recursion will continue indefinitely, causing a stack overflow error and crashing the program.
Click to reveal answer
What is the base case when recursively printing all elements of an array?
✗ Incorrect
The base case is when the index reaches the array length, meaning no more elements to print.
Which of these is a correct recursive step to reverse a string?
✗ Incorrect
The recursive step swaps the first and last characters, then calls itself on the substring inside.
What does a recursive function typically do after processing one element of an array?
✗ Incorrect
After processing one element, the function calls itself with the next element to continue recursion.
Why is a base case important in recursion?
✗ Incorrect
The base case stops recursion to prevent infinite calls and stack overflow.
How can recursion be used to count the number of characters in a string?
✗ Incorrect
Recursion counts 1 for the current character plus the count from the rest of the string.
Describe how recursion works on arrays with an example of summing elements.
Think about stopping condition and how each call handles one element.
You got /4 concepts.
Explain the steps to reverse a string using recursion.
Focus on how the string is reduced each time.
You got /4 concepts.