
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 topDown 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 top-down approach focuses on breaking down a big problem into smaller and understandable chunks. Space complexity is O(N) because we are creating an extra array memory which is equal to the size of number.
Time complexity − O(N)
Space complexity − O(N)
Example
public class DynamicProgramming{ public int fibonacciTopdownApproach(int n,int[] dpArr ){ if(n==0 || n == 1){ return n; } if(dpArr[n] != 0){ return dpArr[n]; } int res = fibonacciTopdownApproach(n - 1,dpArr) + fibonacciTopdownApproach(n - 2,dpArr); return dpArr[n] = res ; } } static void Main(string[] args){ DynamicProgramming dp = new DynamicProgramming(); int[] dpArr = new int[150]; Console.WriteLine(dp.fibonacciTopdownApproach(12, dpArr)); }
Output
144
- Related Questions & Answers
- How to implement coin change problem using topDown approach using C#?
- How to implement minimum step to one using topDown approach using C#?
- How to implement Fibonacci using bottom-up approach using C#?
- How to implement coin change problem using bottom-up approach using C#?
- How to implement minimum step to one using bottom-up approach using C#?
- How to implement the Fibonacci series using lambda expression in Java?
- C++ Program to Find Fibonacci Numbers using Recursion
- C++ Program to Find Fibonacci Numbers using Iteration
- How to print the first ten Fibonacci numbers using C#?
- How to implement Single Responsibility Principle using C#?
- How to implement Open Closed principle using C#?
- How to print the Fibonacci Sequence using Python?
- C++ Program to Find Fibonacci Numbers using Matrix Exponentiation
- C++ Program to Find Fibonacci Numbers using Dynamic Programming
- C++ Program to Compute Discrete Fourier Transform Using Naive Approach
Advertisements