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 tail recursion?

View

What is a benefit of tail recursion?

View

Which of the following recursive functions is an example of tail recursion?

View

Why is tail recursion easier to optimize by the JavaScript engine?

View

Which of these recursive functions is not tail-recursive?

View

Which of the following best describes how a tail-recursive factorial function works?

View

Why might a tail-recursive function still cause stack overflow in JavaScript?

View

What will this tail-recursive function return for sum(5)?

View

How can a traditional recursive function be converted to a tail-recursive one?

View

What does this tail-recursive function return for power(2, 4)?

View

What is tail recursion?

A recursive function that calls itself last in its execution
A recursive function that has no base case
A loop that behaves like recursion
A recursive function that calls itself multiple times

What is a benefit of tail recursion?

It reduces the need for base cases
It can be optimized to avoid stack overflow
It allows infinite recursion
It eliminates recursion completely

Which of the following recursive functions is an example of tail recursion?

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

Yes, because the recursive call is the last operation
No, because it doesn’t use an accumulator
No, because it uses recursion
Yes, because it doesn’t have a base case

Why is tail recursion easier to optimize by the JavaScript engine?

It makes the recursive calls before returning
It eliminates the need to store intermediate results in the call stack
It uses loops instead of recursion
It requires less memory by creating fewer closures

Which of these recursive functions is not tail-recursive?

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

Yes, it is tail-recursive
No, because the result of n + sum(n - 1) is returned
No, because it has no base case
Yes, because it only calls itself once

Which of the following best describes how a tail-recursive factorial function works?

It calculates the result after all recursive calls finish
It passes an accumulator through recursive calls to store intermediate results
It makes recursive calls without using base cases
It uses an iterative loop to calculate the factorial

Why might a tail-recursive function still cause stack overflow in JavaScript?

Tail call optimization is not always supported by JavaScript engines
The function doesn’t use an accumulator
Tail recursion doesn’t actually optimize recursion
Recursion is always less efficient than loops

What will this tail-recursive function return for sum(5)?

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

10
5
15
0

How can a traditional recursive function be converted to a tail-recursive one?

By returning a value immediately without further recursive calls
By adding an accumulator parameter to pass results through recursive calls
By removing the base case
By calling multiple recursive functions

What does this tail-recursive function return for power(2, 4)?

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

16
8
32
4