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 is recursion in JavaScript?

View

What is the purpose of a base case in recursion?

View

What will happen if a recursive function doesn't have a base case?

View

What will the following recursive function output?

View

What is the base case in the following recursive function?

View

How many recursive calls will be made when factorial(4) is executed using this function?

View

What will be the result of calling sum(5) for the following recursive function?

View

Which of the following best describes tail recursion?

View

What will the following recursive function return?

View

What is the termination condition in this Fibonacci recursive function?

View

What is recursion in JavaScript?

A function calling itself
A function calling another function
A loop inside a function
A function that returns a boolean value

What is the purpose of a base case in recursion?

To continue the recursion infinitely
To stop the recursion at some point
To call the function again
To print the final result

What will happen if a recursive function doesn't have a base case?

The function will stop immediately
The function will run only once
The function will result in an infinite loop
The function will return undefined

What will the following recursive function output?

function countDown(n) { if (n <= 0) { console.log("Done"); } else { console.log(n); countDown(n - 1); } } countDown(3);

3 2 1 0 Done
3 2 1 Done
Done 3 2 1
1 2 3 Done

What is the base case in the following recursive function?

function factorial(n) { if (n === 0) { return 1; } else { return n * factorial(n - 1); } }

n === 1
n === 0
n === -1
n === 2

How many recursive calls will be made when factorial(4) is executed using this function?

function factorial(n) { if (n === 0) { return 1; } else { return n * factorial(n - 1); } }

4
5
3
2

What will be the result of calling sum(5) for the following recursive function?

function sum(n) { if (n === 1) { return 1; } else { return n + sum(n - 1); } }

10
15
20
5

Which of the following best describes tail recursion?

The recursive call is the last thing that happens in the function
The recursion is the first thing that happens in the function
The recursion happens inside a loop
The recursive function calls multiple other functions

What will the following recursive function return?

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

6
8
9
4

What is the termination condition in this Fibonacci recursive function?

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

n > 1
n === 2
n <= 1
n === 0