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 the following recursive function output?

View

What is mutual recursion?

View

Which problem does the following recursive function solve?

View

What will be the output of the following recursive function?

View

What is the result of calling isEven(10) using the following mutual recursive functions?

View

What will the following recursive function return?

View

Which of the following recursive functions will result in a stack overflow in JavaScript?

View

What will this recursive function output for fibonacci(6)?

View

How can recursion be optimized in some cases to avoid redundant calls?

View

What does the following recursive function compute?

View

What will the following recursive function output?

function reverseString(str) { if (str === "") { return ""; } else { return reverseString(str.substring(1)) + str[0]; } } console.log(reverseString("javascript"));

tpircsavaj
javascript
tpircs
tpiravaj

What is mutual recursion?

A recursive function that calls itself directly
A function that calls another function which in turn calls the first function
A loop with two recursive functions
A recursive function with two base cases

Which problem does the following recursive function solve?

function gcd(a, b) { if (b === 0) { return a; } else { return gcd(b, a % b); } } gcd(48, 18);

Finding the sum of two numbers
Finding the greatest common divisor (GCD)
Calculating the remainder
Calculating the factorial of a number

What will be the output of the following recursive function?

function sumOfDigits(n) { if (n === 0) { return 0; } else { return (n % 10) + sumOfDigits(Math.floor(n / 10)); } } console.log(sumOfDigits(456));

15
10
6
9

What is the result of calling isEven(10) using the following mutual recursive functions?

function isEven(n) { if (n === 0) return true; return isOdd(n - 1); } function isOdd(n) { if (n === 0) return false; return isEven(n - 1); }

true
false
undefined
An error occurs

What will the following recursive function return?

function multiply(a, b) { if (b === 0) { return 0; } else { return a + multiply(a, b - 1); } } multiply(4, 3);

12
7
9
6

Which of the following recursive functions will result in a stack overflow in JavaScript?

A recursive function without a base case
A recursive function with a base case
A recursive function with multiple base cases
A function that recursively calls itself once

What will this recursive function output for fibonacci(6)?

function fibonacci(n) { if (n <= 1) { return n; } else { return fibonacci(n - 1) + fibonacci(n - 2); } }

8
13
5
21

How can recursion be optimized in some cases to avoid redundant calls?

By adding more base cases
By using a while loop instead
By applying memoization to store previous results
By reducing the number of recursive calls

What does the following recursive function compute?

function power(base, exp) { if (exp === 0) { return 1; } else { return base * power(base, exp - 1); } } power(2, 4);

8
16
4
32