September 2019
Intermediate to advanced
816 pages
18h 47m
English
Commonly denoted as Fn, the Fibonacci numbers are a sequence that respects the following formula:
F0=0, F1 = 1, ... Fn = Fn-1 + Fn-2 (n > 1)
A snapshot of Fibonacci numbers is:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...
The implementation of Fibonacci numbers via RecursiveAction can be accomplished as follows:
public class FibonacciRecursiveAction extends RecursiveAction { private static final Logger logger = Logger.getLogger(FibonacciRecursiveAction.class.getName()); private static final long THRESHOLD = 5; private long nr; public FibonacciRecursiveAction(long nr) { this.nr = nr; } @Override protected void compute() { final long n = nr; if (n <= THRESHOLD) { nr = fibonacci(n); } else { nr = ...