
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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 Articles
- 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?
- How to print the first ten Fibonacci numbers using C#?
- C++ Program to Find Fibonacci Numbers using Recursion
- C++ Program to Find Fibonacci Numbers using Iteration
- 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 Dynamic Programming
- C++ Program to Find Fibonacci Numbers using Matrix Exponentiation
- How to implement Dependency Injection using Property in C#?

Advertisements