Test Your Knowledge 5
Test your understanding of recursion with arrays by answering quiz questions that cover counting, reversing, replacing, averaging, balancing, and sorting. This lesson helps you prepare for applying recursion to data structures in coding interviews.
We'll cover the following...
We'll cover the following...
Quiz on Arrays
This Quiz will take approximately 10 minutes.
1.
The function below prints a string recursively, meaning that one character is printed in each recursive call.
function printArray(array, startIndex, length) {
// Base case
____________________________________
console.log(array[startIndex] + "\t")
// Recursively calling printArray to print next element in the array
printArray(array, startIndex + 1, length)
}
What should the base case of the following code be?
A.
if (startIndex >= length) {
return
}
B.
if (startIndex <= length) {
return
}
C.
if (startIndex >= length/2) {
return
}
D.
if (startIndex >= 0) {
return
}
1 / 4
In the next chapter, we will use recursion to solve problems with data structures.