Add time complexity of Fibonacci with recursion

pull/1066/head
4kpros 2022-10-22 00:23:11 +01:00
parent b95504a57e
commit 7a445d0e13
1 changed files with 6 additions and 2 deletions

View File

@ -1,20 +1,24 @@
/*
Description: Program to calculate fibonacci using recursion
Time complexity: O(2^n) where n is the number
*/
#include <iostream>
using namespace std;
//Recursive function with integer parameter
int RecursiveFibonacci(int number)
{
if(number == 1 || number == 2)
if(number == 0 || number == 1)
return 1;
if(number >= 3)
if(number >= 2)
return RecursiveFibonacci(number - 1) + RecursiveFibonacci(number - 2);
return 0;
}
//Main function
int main(int argc, char *argv[])
{
int number = 10;