Add time complexity of Fibonacci with recursion
parent
b95504a57e
commit
7a445d0e13
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue