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.
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) endStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started