02 - Fibonacci Numbers - Recursive

@Rishi Srivastava In mathematics, the Fibonacci numbers form a sequence, the Fibonacci sequence, in which each number is the sum of the two preceding ones. Starting from 0 and 1, the next few values in the sequence are: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144 Formula: F(n) = F(n-1) F(n-2) {for n greater than 1} Recursive algorithm pseudocode: function fib(n): if n is less than 0, then return undefined if n is less than 2, then return n return fib(n-1) fib(n-2) Time complexity: O(2^n) Space complexity: O(n) if we consider the recursive stack ERRATA: The total time taken is not 6.7 seconds but the ms given in the output Github:
Back to Top