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

Sockets - Cyndi #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
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
18 changes: 15 additions & 3 deletions lib/fibonacci.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,20 @@
# ....
# e.g. 6th fibonacci number is 8

# Time complexity: ?
# Space complexity: ?
# n is the input number
# Time complexity: O(2n), since 2n steps will be needed.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect. Each function call generates two additional function calls, so time complexity is really O(2^n).

# Space complexity: O(n), the call stack will be at most n deep.
def fibonacci(n)
raise NotImplementedError
p "here"
if n.nil? || n < 0
raise ArgumentError
end
if n == 0
return 0
elsif n == 1
# p "n = 1"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a useful comment. Remove.

return 1
else
return fibonacci(n - 2) + fibonacci(n - 1)
end
end