DUE DATE: Sunday, 11:30am, September 30th

 

GRADING

 

• Calculate the nth element of a Fibonacci sequence using simple iteration – 4 points

 

• Calculate the nth element of a Fibonacci sequence using recursion – 4 points

 

• Determine the number of operations needed for various values of n (n=1, n=5, n=10, n=20) in the recusrive and iterative approach. – 2 points

 

OBJECTIVE

 

Gain experience in using the Java w.r.t iteration and recursion. Additionally to understand differences in efficiency using Big O.

 

BACKGROUND

In mathematics, Fibonacci sequence is a mathematical sequence defined by the following recurrence relation:


 

If n=10, then the Fibonacci series would be: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55.

 

In computer science theory, big O notation is often used to describe how the size of the input data affects an algorithm's usage of computational resources (usually running time or memory). It is also called Big Oh notation.

 

Computational complexity for the calculating the Fibonacci series using iteration = O(n) ( Linear growth)

 

Computational complexity for the calculating the Fibonacci series using recursion = O(2^n) (2 to the power n)  ( Exponential growth rate)

 

Below is the comparison graph of the running times of the iterative program and the recursive program for generating the Fibonacci series

 

 

The graph shows that up to about n=35, the running times of the two algorithms are comparable. However, as n increases past 40, the exponential growth rate of the recursive program is clearly evident.

 

 

ASSIGNMENT

There are skeletons of two java programs

 

a)         FiboIterate.java – to calculate the Fibonacci sequence using iteration

 

b)                 FiboRecurse.java – to calculate the Fibonacci sequence using recursion

 

Please fill in the necessary function calls and print statements as specified in the .java files

 

SUBMIT

 

Create a JAR file containing all your source code (.JAVA and .CLASS files). Submit using webCT. Make sure your JAR file has the .JAVA files.

 

 If the source files are not included then you will not receive any grades for the assignment.