Instructions
- 1. Your final score will reflect your grasp of the concepts—approach each question with precision.
- 2. Thoroughly review each solution before proceeding to ensure full understanding.
- 3. Final results will be available after submission to provide insights into areas for further improvement.
- 4. Maintain academic integrity—plagiarism undermines learning and professional growth.
- 5. Once submitted, responses are final, so ensure you’re confident in your answers.
- 6. These challenges are designed to test practical knowledge; apply your skills as you would in real-world scenarios.
All Problems
Question
Action
What will this recursive function return?
Which base case will correctly terminate this recursive function for finding the maximum element in an array?
What will this function return when called with flatten([1, [2, 3], [4, [5]]])?
What does the following recursive function do?
What is the time complexity of the following function for summing an array?
What does the following code output for findMin([5, 3, 9, 1, 4])?
Which of the following is true for this recursive function?
What is the role of the slice method in recursive array algorithms?
What will this code return for arrayProduct([2, 3, 4])?
What does the following recursive function return?
What will this recursive function return?
function sumArray(arr) { if (arr.length === 0) { return 0; } else { return arr[0] + sumArray(arr.slice(1)); } } sumArray([1, 2, 3, 4]);
Which base case will correctly terminate this recursive function for finding the maximum element in an array?
function findMax(arr) { if (arr.length === 1) { return arr[0]; } // recursive step... }
What will this function return when called with flatten([1, [2, 3], [4, [5]]])?
function flatten(arr) { if (!Array.isArray(arr)) { return [arr]; } return arr.reduce((acc, curr) => acc.concat(flatten(curr)), []); }
What does the following recursive function do?
function countDown(n) { if (n === 0) { return []; } else { return [n].concat(countDown(n - 1)); } }
What is the time complexity of the following function for summing an array?
function sumArray(arr) { if (arr.length === 0) { return 0; } else { return arr[0] + sumArray(arr.slice(1)); } }
What does the following code output for findMin([5, 3, 9, 1, 4])?
function findMin(arr) { if (arr.length === 1) { return arr[0]; } let restMin = findMin(arr.slice(1)); return arr[0] < restMin ? arr[0] : restMin; }
Which of the following is true for this recursive function?
function allEven(arr) { if (arr.length === 0) { return true; } return arr[0] % 2 === 0 && allEven(arr.slice(1)); }
What is the role of the slice method in recursive array algorithms?
What will this code return for arrayProduct([2, 3, 4])?
function arrayProduct(arr) { if (arr.length === 0) { return 1; } else { return arr[0] * arrayProduct(arr.slice(1)); } }
What does the following recursive function return?
function isPalindrome(str) { if (str.length <= 1) { return true; } if (str[0] !== str[str.length - 1]) { return false; } return isPalindrome(str.slice(1, -1)); }