mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-09-20 07:43:04 +08:00
Added a recursive code for finding the fibonacci series
Hey, I added a recursive code for the fibonacci problem. Hope you merge it
This commit is contained in:
parent
76617fa83a
commit
726a7149a4
@ -27,3 +27,16 @@ export default function fibonacci(n) {
|
|||||||
|
|
||||||
return fibSequence;
|
return fibSequence;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Return a fibonacci series using recursion
|
||||||
|
* Time Complexity -- O(2^N)
|
||||||
|
* Space Complexity -- O(N)
|
||||||
|
*/
|
||||||
|
export default function fib(int n){
|
||||||
|
if(n==1 || n==0){
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return fib(n-1)+fib(n-2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user