Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

ID: 3798027 • Letter: H

Question

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.

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

Explanation / Answer

-------------------------------------------------------------------------------------------------------------

if n=5 , then last two fibonacci number is 2,3(f=2,s=3)

Example if n=5

---------------------------------------------------------------------------------------------

If you have any query, please feel free to ask.

Thanks a lot.