Code Monkey home page Code Monkey logo

fibonacci's Introduction

Fibonacci: recursion vs iteration.

The purpose of this exercise is not to determine what method of calculating a Fibonacci sequence would be more efficient in computational terms.

What does this program do?

The program calculates the Fibonacci sequence, both recursively and iteratively, for a specific number of passes, while calculating the time it takes to perform the calculations for each pass. The time is calculated in nanoseconds.

It is expected that for the smaller number of passes, the calculation times will be smaller. As the number of passes grows, so will the time to perform each calculation.

The program will run all 35 passes twenty times, so as to get a large data set to graph and compare results. Each time 35 passes are run, the program will output the timing data into a CSV (comma separated values) file, which can then be used to graph the results and determine what calculation is more computationally efficient.

Code design.

The code for this program has been divided into two parts. First, a class FibonacciFunctions that contains the two calculation methods. Second, a class FibonacciImplementation that calls the FibonacciFunctions, calculates the time of the calculations and finally outputs the CSV file for graphing the results.

Test plans and standards.

For the sake of speed and simplicity, the code was not test driven. In other words, no unit tests were used to test the code or the outputs. Testing was done in two stages. First, to test that the Fibonacci sequence was properly generated in each pass, by outputting each of the numbers of the sequence that corresponded to each pass. Since output to the console during the calculations would add an unnecessary overhead thereto, the numbers will not be output to the console once testing is concluded.

System requirements.

The code is not dependent on any specific JDK. However, the code was compiled and tested using version Amazon's distribution of the Open Java Development Kit (OpenJDK) Corretto 11.

How to use this program.

The program requires no user interaction other than compilation and execution. User may, however, decide to test the program with increased or reduced number of passes. To do so, the value assigned to the static variable iterations can be changed. Be careful, though. It is expected that a high number of passes will take much longer to execute the recursive method, which theoretically makes heavy use of stack memory, and may hang your system.

Installation.

To install the program, simply clone the repo and open it in your favorite IDE. As stated in system requirements above, it is not JDK dependent, and should work out-of-the-box with any current JDK.

Known Issues

After the program outputs the results to CSV files, the task of compiling the results is tedious. There is too much transposing involved before the charts can be generated. This will require additional coding to properly output the results to two CSV files instead of several files for later processing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.