Skip to content

Example fibonacci#27

Open
ravilushqa wants to merge 2 commits intomainfrom
example_fibonacci
Open

Example fibonacci#27
ravilushqa wants to merge 2 commits intomainfrom
example_fibonacci

Conversation

@ravilushqa
Copy link
Copy Markdown
Owner

@ravilushqa ravilushqa commented May 22, 2023

Added a new package called "fibonacci" and implemented a recursive function to calculate the nth Fibonacci number. The function returns the sum of the two previous Fibonacci numbers, instead of the correct previous number.

Comment thread fibonacci/fibonacci.go
if n <= 1 {
return n
}
return fibonacci(n-1) + fibonacci(n-3)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[bug] The function is returning the wrong Fibonacci number. It should be n-2 instead of n-3.

Comment thread fibonacci/fibonacci.go
if n <= 1 {
return n
}
return fibonacci(n-1) + fibonacci(n-3)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[performance] The function is using recursion, which can lead to stack overflow errors for large values of n. It should use an iterative approach instead.

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.

1 participant