Contents
Learn Fibonacci Series calculation using Dynamic Programming in Java using Hashmap
INPUT:Element Number (N)
OUTPUT: SUM OF ELEMENT OF THE FIBONACCI SERIES
Data Structure: Recursive Stack and HashMap
STEP 1: START
STEP 2: FIBO(N)
STEP 3: IF(N<=1)
STEP 4: RETURN N
STEP 5: RETURN FIBO(N-1)+FIBO(N-2)
STEP 6: STOP Code
import java.util.*;
class dp{
static HashMap<Integer,Integer> ob=new HashMap<>();
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
System.out.println("ENTER THE NUMBER");
int n=sc.nextInt();
System.out.println(fibo(n));
}
public static int fibo(int n){
if(ob.containsKey(n)){
return ob.get(n);
}
if(n<=1)
return n;
int res=fibo(n-1)+fibo(n-2);
ob.put(n,res);
return res;
}
} Output
user@computer$ ENTER THE NUMBER
9
34
Related Posts
- Array Traversal Code and Algorithm
INPUT:Array with lower bound(l) and upper bound(u)OUTPUT:ELEMENT PRESENT IN THE ARRAYData Structure: Single Dimensional ArraySTEP…
- How to Delete Element from an Array.
This post covers the procedure, algorithm, and code on how to delete elements from an…
- Reversing an Array: How to reverse the elements of an Array.
This post covers array reversal meaning reversing all the elements of an array. The left-most…

