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

Completed fibonacci challenge #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Completed fibonacci challenge #13

wants to merge 1 commit into from

Conversation

cassyarchibald
Copy link

No description provided.

@shrutivanw
Copy link

Nice work attempting both iterative and recursive solutions.

The space complexity of your iterative algorithm is O(n) because you're maintaining a results array. The results array will get as large as the input parameter, n before the final result is computed and returned. Can you think of how you may tweak the algorithm to not require the results' array and instead only maintain the previous two fibonacci numbers computed thus far in two separate integer values? Once you've given it some thought, compare your improved algorithm with mine on https://github.com/Ada-C10/fibonacci/blob/solution/lib/fibonacci.rb

As you called out, the recursive approach, like the one you attempted takes much longer. It requires exponential time complexity to be precise i.e. O(2 ^ n). It also needs the call stack space which takes up O(n) space. We will be looking at this recursive approach to fibonacci later in class. Feel free to take a look at the later slides in https://drive.google.com/file/d/0B__DV26QHsH4bWJmS1A0QXBad1U/view?usp=sharing if you're curious. (P.S: play the slide show in Google slides so you can see the animations)

Slack me if you'd like to discuss further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants