by Konstantin Gredeskoul, with many examples borrowed from around the Internet.
This repo is a learning project, aimed at keeping together various projects, and following a consistent structure.
This little program offers three different implementations of computing a Fibonacci sum:
- A non-optimized recursive algorithm that gets really slow for N > 47
- An optimized recursive algorithm that uses memoization (a map) to keep all pre-computed values.
- A linear algorithm that computes Fib sum without recursion.
Running
❯ go run fibonacci.go 0 1 10 40
0 0
1 1
10 55
40 102334155
————————————————————————————————————————————
run_non_recursive took 41.121µs seconds
0 0
1 1
10 55
40 102334155
————————————————————————————————————————————
run_recursive_memo took 22.354µs seconds
0 0
1 1
10 55
40 102334155
————————————————————————————————————————————
run_recursive took 623.745ms seconds