19.2 Recursion (3)

Resources | Revision Questions | Computer Science

Login to see all questions

Click on a question to view the answer

1.

Question 3

Describe a scenario where recursion is a particularly well-suited approach to solving a problem. Explain why recursion is advantageous in this scenario, and outline the potential drawbacks to consider. Provide a specific example using a simple algorithm.

2.

Question 2

Consider the following recursive function: def fibonacci(n): if n . This function is intended to calculate the nth Fibonacci number. However, it is very inefficient. Explain why this implementation is inefficient, and describe an alternative, more efficient approach to calculating Fibonacci numbers. You should consider the time complexity of both approaches.

3.

Question 1

A compiler needs to perform several distinct phases to translate a recursive program into executable code. Describe, in detail, at least four key phases involved in this translation process. For each phase, briefly explain its purpose and the type of output it generates.