CSE 1302 Project 4: Calculating Fibonacci Sequence, Study Guides, Projects, Research of Computer Science

A programming project for cse 1302 students, where they are required to write both recursive and iterative functions to calculate the nth element of a fibonacci sequence. The document also includes instructions on how to time the function calls and print the sequence up to the 40th element.

Typology: Study Guides, Projects, Research

Pre 2010

Uploaded on 08/03/2009

koofers-user-ogv
koofers-user-ogv 🇺🇸

9 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSE 1302 Project 4 – Fibonacci Sequence
Due: April 8, 2009
Write a recursive and an iterative function to calculate the nth element in a
Fibonacci sequence. A Fibonacci sequence is defined as the element 1,
followed by another 1, and each element thereafter is the sum of the
previous two elements. For example, the first 9 elements of a Fibonacci
sequence are:
1 1 2 3 5 8 13 21 34
This famous sequence was originally used to predict the growth of rabbit
populations!
Once you have each of the functions working for n equal to 40, determine
which method is more efficient by timing the two separate function calls and
print out the time required for each call and the 40th element in the sequence.
After that, print out a complete Fibonacci sequence from element 1 to
element 40. This last part should not be timed.
The timer function you need for Project#4 is:
Date d1 = new Date();
long milliseconds = D1.getTime();
OR
long start = System.currentTimeMillis();
You can check the appendix in your text for more information on Date methods (page
804-805) or System methods (page 892-893).
Additional handout of information available from instructor
Turn in the source, output and a short paragraph explaining the reason the
two methods took different amounts of time to execute.
Extra Credit: Find a recursive method that has not been covered in class or
in your text. Code it, run it, and turn in the source and output with
Project#4.

Partial preview of the text

Download CSE 1302 Project 4: Calculating Fibonacci Sequence and more Study Guides, Projects, Research Computer Science in PDF only on Docsity!

CSE 1302 Project 4 – Fibonacci Sequence Due: April 8, 2009 Write a recursive and an iterative function to calculate the nth element in a Fibonacci sequence. A Fibonacci sequence is defined as the element 1, followed by another 1, and each element thereafter is the sum of the previous two elements. For example, the first 9 elements of a Fibonacci sequence are: 1 1 2 3 5 8 13 21 34 This famous sequence was originally used to predict the growth of rabbit populations! Once you have each of the functions working for n equal to 40, determine which method is more efficient by timing the two separate function calls and print out the time required for each call and the 40th^ element in the sequence. After that, print out a complete Fibonacci sequence from element 1 to element 40. This last part should not be timed. The timer function you need for Project#4 is: Date d1 = new Date(); long milliseconds = D1.getTime(); OR long start = System.currentTimeMillis(); You can check the appendix in your text for more information on Date methods (page 804-805) or System methods (page 892-893). Additional handout of information available from instructor Turn in the source, output and a short paragraph explaining the reason the two methods took different amounts of time to execute. Extra Credit: Find a recursive method that has not been covered in class or in your text. Code it, run it, and turn in the source and output with Project#4.