Memorizationisusedliterallyeverywhere, insideofprogramming, andsomereallypopularusecasesarethiswhereyouhave a reallyslowfunctionthattakes a longtimetoexecute, andyouwanttogetthesamevalueoverandover.
Anotherreallypopularusecaseiswhenyou'refetching.
Externalresourceissoyou'reusingthefetch a P I.
Thenusingmemorizationwillsaveyoufromhavingtomake a bunchofcallstotheserver.
Thelastmajorusecaseofmemorizationisindynamicprogramminganddynamicprogrammingiswhenyoutake a recursivefunctionthatcallsitselfmultipletimeswithsameinputsandyouactuallymemewisethoseinputs.
Soifyou'renotfamiliarwithrecursivefunctions, I haveanentirevideoonthem.
So a creditfunctioncalledfib, whichtakesanend, whichistheendofthenumberoftheFibonaccisequencewewanttogetandwiththeFibonaccisequence, ifendiseitherequaltooneortwo.
Sowe'rerepeating a bunchoftheseFibonaccicalls, whichiswherewecandomemorizationsowecanjustcomeinhereandwecansaythatwewanttocalculateourpreviousvaluesandwilldefaultthistoanemptyraysowecanactuallypassthesepreviousvaluesintoourotherFibonaccisequenceissaying, Hey, we'vealreadycalculatedthis.
Youdon't needtorecalculateit, andthenwejustdo a verysimilarthingtowhatwedidwiththatsquarefunction.
Sothefirstthing I wanttodoiswe'regonnacreate a variableRynercalledusourresultsjustlikethat.
Giveitaboutequal.
Andthenherewejustwanttosetourresultequaltoeoneifitislessthanorequaltotwo, andherewe'regonnaset a resultequaltothefifthandminusonepositiveof n minustwo.
Now, whatwecandoiswecanactuallytakeourpreviousvaluesof N.