Professional Documents
Culture Documents
Assignment 1
Assignment 1
# 1 (a) Write a program to calculate the nth Fibonacci number using both recursive and
iterative algorithm. Your program will have the following specifications:
It will take in a number (n) as input from user and compute the nth Fibonacci number.
It will also compute the time taken by both algorithms to generate the result respectively.
Input:
Output:
[These are not calculated results, hence no need to panic if your answers dont match with these
(in fact it would be surprising if they did) as they just serve as an example].
(b) Use the program to calculate the Fibonacci number for different number (n). Draw a graph of
the time taken by both algorithms as n is increased, with time on y-axis and n on x-axis.
[Plot the results for both the algorithms on the same graph].
# 2 (a) Show whether f(n) is Big O of g(n) or not, in the following cases.
f(n) g(n)
n-100 n-200
n3 + 20n + 1 n2
3n2 + 4n + 1 n2