Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 71c93f7

Browse files
DOCS Added code examples section
1 parent 73b142a commit 71c93f7

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

‎README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,23 @@
1212
8. Fibonacci.fib()
1313
9. Fibonacci.fast_fib()
1414

15+
## Code Examples
16+
One interesting implementation is this algorithm to compute fibonacci sequences, it runs in O(1) time provided that the cache contains the previous two sequences. Generating the previous sequences is usually done using loops.
17+
```python3
18+
@staticmethod
19+
def fast_fib(n: int, cache: {int: int}) -> int:
20+
"""Fibonacci sequence algorithm utilizing dynamic programing and memoization"""
21+
if n == 0:
22+
cache[n] = 0
23+
return 0
24+
25+
if n == 1:
26+
cache[n] = 1
27+
return 1
28+
29+
cache[n] = cache[n - 2] + cache[n - 1]
30+
return cache[n]
31+
```
32+
1533
## Java Implementation
1634
These were originally implemented in Java. You can find the source [here](https://github.com/dev-xero/java-algorithms-exercise-practice)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /