Added a new Java Recursive program.

pull/1129/head
Nishanth Chandra 2023-01-03 18:41:05 +05:30 committed by GitHub
parent aba1357a9c
commit b4ab197eb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1,25 @@
package com.dsa;
/* Description: To find the Nth Fibonacci Number
Time Complexity: O(n) where n is the number inputted
*/
public class Fibonacci {
public static int Fibo(int n){
if(n < 2){ // base condition
return n;
}
return Fibo(n-1) + Fibo(n-2); //linear recurrence relation
}
public static void main(String[] args) {
System.out.println(Fibo(5));
}
/* Sample Input
n = 5
Output:
5
*/
}