Question: Help me understand this SML algorithm: The purpose of the algorithm is to calculate the n th fibonacci number in linear time. It uses standard

Help me understand this SML algorithm:

The purpose of the algorithm is to calculate the nth fibonacci number in linear time. It uses standard ML and its pairing construct. I understand fibAux is just a helper function to boil down the algorithm and extract the solution at the end but don't understand on a step by step basis how it works...like if n=5 how does that translate down the line to (f,s) input values and a (s,f+s) result. Just started learning the language today and need someone to explain in layman's terms how this works and why it's faster than the most basic form of the algorithm.

Help me understand this SML algorithm: The purpose of the algorithm is

C fast one with pairing fun fibFast n let fun fibAux 0 C0,0) I fibAux 1 C0, 1) l fibAux n let val Cf.s fibAux Cn-1) in CSAf+s) end in #2 fibAux n) end

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!