Difference between revisions of "Fibonacci"
| Line 59: | Line 59: | ||
:: <math>k = \dfrac{n+1}{2}</math> | :: <math>k = \dfrac{n+1}{2}</math> | ||
| − | :: <math>F_n = (F_{k} | + | :: <math>F_n = (F_{k} \times F_{k}) + (F_{k-1} \times F_{k-1})</math> |
:else | :else | ||
| Line 65: | Line 65: | ||
:: <math>k = \dfrac{n}{2}</math> | :: <math>k = \dfrac{n}{2}</math> | ||
| − | :: <math>F_n = ((2 | + | :: <math>F_n = ((2 \times F_{k-1}) + F_{k}) \times F_{k}</math> |
===seed values=== | ===seed values=== | ||
Revision as of 14:10, 7 October 2017
Contents
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
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
implement a recursive method for:
recurrence relation
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle F_n = F_{n-1} + F_{n-2}}
seed values
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle F_0=0}
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle F_1=1}
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
recurrence relation
- if n is odd
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle k = \dfrac{n+1}{2}}
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle F_n = (F_{k} \times F_{k}) + (F_{k-1} \times F_{k-1})}
- else
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle k = \dfrac{n}{2}}
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle F_n = ((2 \times F_{k-1}) + F_{k}) \times F_{k}}
seed values
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle F_0=0}
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle F_1=1}
RoundPhiToTheNOverSqrt5SequentialFibonacciCalculator
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle \dfrac{\Phi^n}{\sqrt{5}}}