|
|
|
|
|
by firebacon
1918 days ago
|
|
Interesting to consider the total complexity of that approach though. An iterative fibonacci solution runs in linear time. Calculating the N'th fibonacci number requires O(N) serial operations. A fully parallel, recursive solution without memoization requires that each value in the sequence is computed more than once. Consider the example of fib(4): fib(4) = fib(3) + fib(2)
fib(3) = fib(2) + fib(1)
fib(2) = fib(1) + fib(0)
You can see, that if we run this in parallel, the value of fib(1) has to be calculated twice. As the tree of operation branches out, more and more duplicate calculations are required.A quick google suggests that the time complexity of the recursive approach is O(2^N). |
|
Absolutely nobody is under the impression that the naive parallel implementation of fib is actually useful code or the most efficient way to do it. You're missing the point if you're suggesting a different way to do it in the first place.
It's just something to use as a running example... like on the original article this whole thread is about.