Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to implement Fibonacci using bottom-up approach using C#?
The Fibonacci sequence is a set of numbers that starts with a one or a zero, followed by a one, and proceeds based on the rule that each number (called a Fibonacci number) is equal to the sum of the preceding two numbers. The bottom-up approach first focuses on solving the smaller problems at the fundamental level and then integrating them into a whole and complete solution.
Time complexity − O(N)
Space complexity − O(N)
Example
public class DynamicProgramming{
public int fibonacciBottomupApproach(int n){
int[] dpArr = new int[150];
dpArr[1] = 1;
for (int i = 2; i <= n; i++){
dpArr[i] = dpArr[i - 1] + dpArr[i - 2];
}
return dpArr[n];
}
}
static void Main(string[] args){
DynamicProgramming dp = new DynamicProgramming();
Console.WriteLine(dp.fibonacciBottomupApproach(5));
}
Output
5
Advertisements