Difference between revisions of "Fibonacci"

From CSE231 Wiki
Jump to navigation Jump to search
Line 14: Line 14:
 
[http://www.cs.rice.edu/~vs3/hjlib/doc/edu/rice/hj/api/HjFuture.html interface HjFuture<V>].   
 
[http://www.cs.rice.edu/~vs3/hjlib/doc/edu/rice/hj/api/HjFuture.html interface HjFuture<V>].   
 
# [http://www.cs.rice.edu/~vs3/hjlib/doc/edu/rice/hj/api/HjFuture.html#get-- get()]
 
# [http://www.cs.rice.edu/~vs3/hjlib/doc/edu/rice/hj/api/HjFuture.html#get-- get()]
 +
 +
=Common Mistakes To Avoid=
 +
==use Habanero's HjFuture<V>, NOT java.util.concurrent's Future<V>==
 +
 +
Check out [[Habanero#Future]] for pointers on using Habanero's futures.
 +
 +
==use long, NOT int==
 +
lambdas will get cranky if you try to return an int instead of a long.
 +
 +
also, if you use ints in your calculation you will fail the tests when the result goes over [https://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html#MAX_VALUE Integer.MAX_VALUE].
  
 
=Studio (Required)=
 
=Studio (Required)=
Line 38: Line 48:
 
==RoundPhiToTheNOverSqrt5SequentialFibonacciCalculator==
 
==RoundPhiToTheNOverSqrt5SequentialFibonacciCalculator==
 
<math>\dfrac{\Phi^n}{\sqrt{5}}</math>
 
<math>\dfrac{\Phi^n}{\sqrt{5}}</math>
 
=Common Mistakes To Avoid=
 
==use Habanero's HjFuture<V>, NOT java.util.concurrent's Future<V>==
 
 
Check out [[Habanero#Future]] for pointers on using Habanero's futures.
 
 
==use long, NOT int==
 
lambdas will get cranky if you try to return an int instead of a long.
 
 
also, if you use ints in your calculation you will fail the tests when the result goes over [https://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html#MAX_VALUE Integer.MAX_VALUE].
 

Revision as of 11:03, 3 October 2017

Background

The fibonacci sequence is a mathematical concept often used in computer science as a means to demonstrate iteration and recursion. Although you should be familiar with it from CSE 131, we will use the fibonacci sequence to demonstrate memoization and dynamic programming. Follow these links for a quick recap on memoization, dynamic programming, and the fibonacci sequence.

Where to Start

You will need to return the number associated with a given position in the fibonacci sequence. For example, if 0 was fed in, the method should return 0. 1 should return 1, 2 should return 1, 3 should return 2, and so on.

JUnit Test Suite

FibonacciTestSuite

Javadocs

Habanero

  1. future(body)

interface HjFuture<V>.

  1. get()

Common Mistakes To Avoid

use Habanero's HjFuture<V>, NOT java.util.concurrent's Future<V>

Check out Habanero#Future for pointers on using Habanero's futures.

use long, NOT int

lambdas will get cranky if you try to return an int instead of a long.

also, if you use ints in your calculation you will fail the tests when the result goes over Integer.MAX_VALUE.

Studio (Required)

RecurrenceRelationSequentialFibonacciCalculator

recurrence relation:

seed values:

RecurrenceRelationParallelFibonacciCalculator

Use futures to add parallelism to the recurrence relation solution.

MemoizationSequentialFibonacciCalculator

Implement the recurrence relation algorithm but employ memoization for the win.

MemoizationParallelFibonacciCalculator

Create all of your futures [0..N] up front and then call get on memo[n].

DynamicIterativeSequentialFibonacciCalculator

Fun (Optional)

DynamicRecursiveSequentialFibonacciCalculator

LinearRecurrenceSequentialFibonacciCalculator

RoundPhiToTheNOverSqrt5SequentialFibonacciCalculator