Resources | Revision Questions | Computer Science
Click on a question to view the answer
Write efficient pseudo-code to calculate the nth Fibonacci number using recursion. Consider the potential for inefficiency and suggest a way to improve the algorithm's efficiency.
Describe how the use of procedures can improve the efficiency of an algorithm. Consider both time complexity and space complexity in your answer.
A student has written the following code in a programming language (you do not need to identify the specific language). The code is intended to calculate the sum of the first 'n' natural numbers. Identify the potential problems with this code in terms of its design and explain how a procedure could be used to improve it. Provide a brief example of how the improved code might look.
sum = 0 for i = 1 to n sum = sum + i print sum