Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:scriptsamples:fibonacci [2015/09/14]
127.0.0.1 external edit
developer:scriptsamples:fibonacci [2015/12/04] (current)
sandy
Line 1: Line 1:
 ====== Fun with Fibonacci Numbers ====== ====== Fun with Fibonacci Numbers ======
 > **Developer:​** //​[[developer:​rhinoscript|RhinoScript]]//​ > **Developer:​** //​[[developer:​rhinoscript|RhinoScript]]//​
-> **Summary:​** //A survey of Fibonacci number algorithms.//+> **Summary:​** //A survey of Fibonacci number algorithms//​
  
-=====More ​Information=====+=====More ​information=====
 [[http://​en.wikipedia.org/​wiki/​Fibonacci_number|Fibonacci numbers]] [[http://​en.wikipedia.org/​wiki/​Fibonacci_number|Fibonacci numbers]]
  
Line 15: Line 15:
 </​code>​ </​code>​
  
-with seed values:+With seed values:
  
 <code vb> <code vb>
Line 22: Line 22:
 </​code>​ </​code>​
  
-There are a number of methods that one can use to calculate these numbers. Here are a few:+There many methods that one can use to calculate these numbers. Here are a few:
  
 ====1. Recursion==== ====1. Recursion====
Line 40: Line 40:
 </​code>​ </​code>​
  
-====2. Dynamic ​Iteration====+====2. Dynamic ​iteration====
 One of the reasons the recursive algorithm can be slow is we keep recomputing the same subproblems over and over again. In this iterative approach, we solve each subproblem once and then look up the solution later when we need it instead of repeatedly recomputing it. One of the reasons the recursive algorithm can be slow is we keep recomputing the same subproblems over and over again. In this iterative approach, we solve each subproblem once and then look up the solution later when we need it instead of repeatedly recomputing it.
  
Line 63: Line 63:
 </​code>​ </​code>​
  
-====3. Space Complexity Iteration====+====3. Space complexity iteration====
 It turns out that the dynamic iteration can be modified to use a much smaller amount of space. Each step through the loop uses only the previous two values of F(n), so instead of storing these values in an array, we can simply use two variables. This requires some swapping around of values so that everything stays in the appropriate places. It turns out that the dynamic iteration can be modified to use a much smaller amount of space. Each step through the loop uses only the previous two values of F(n), so instead of storing these values in an array, we can simply use two variables. This requires some swapping around of values so that everything stays in the appropriate places.
  
developer/scriptsamples/fibonacci.txt ยท Last modified: 2015/12/04 by sandy