Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Fibonacci solution w/ recursion and memoization #268

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add README-recursive.md explaining code
There's already a README.md file in the folder so I couldn't come up with a better name, this is of course subject to change.
mateusmlo authored Dec 12, 2018

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit a4c37d88d2a0d8b2265be5c45d46a2747f38b584
19 changes: 19 additions & 0 deletions src/algorithms/math/fibonacci/README-recursive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Fibonacci recursive function using memoization as a decorator

The Fibonacci algorithm in its recursive form may be considered cursed by the majority of developers (because it is), but there is a way to make it work: using memoization. The memoize function is a closure and needs another function as an argument, then its result is checked on the Map object; if it's there, return it, if not, add it to the Map. As the algorithm grows in size, it will only return references rather than computing values over and over again.

## Memoization

In computing, memoization or memoisation is an optimization technique used primarily to speed up computer programs by storing the results of expensive function calls and returning the cached result when the same inputs occur again. Memoization has also been used in other contexts (and for purposes other than speed gains), such as in simple mutually recursive descent parsing. Although related to caching, memoization refers to a specific case of this optimization, distinguishing it from forms of caching such as buffering or page replacement. In the context of some logic programming languages, memoization is also known as tabling.

## Recursion

Recursion in computer science is a method of solving a problem where the solution depends on solutions to smaller instances of the same problem (as opposed to iteration).[1] The approach can be applied to many types of problems, and recursion is one of the central ideas of computer science.

## Closure
More info on closures here: https://javascript.info/closure

## References
- [Wikipedia](https://en.wikipedia.org/wiki/Memoization)
- [Wikipedia](https://en.wikipedia.org/wiki/Recursion_(computer_science))
- [JavaScript.info](https://javascript.info/closure)