Skip to content

Performance or Space Which is the best option for your optimization. In this project I created a two path using Fibonacci Calculation for this situation

Notifications You must be signed in to change notification settings

oguzhandelibas/FibonacciCalculation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Performance-vs-Space

Performance or Space. Which is the best option for your optimization. In this project I created a two path using Fibonacci Calculation for this situation

Memory Friendly Calculation - 4802ms

WindowsTerminal_pngRmw8pXh

int SlowFib(int n)
{
    if (n == 1) return 1;
    else if (n == 2) return 1;
    else
        return (SlowFib(n - 1) + SlowFib(n - 2));
}

void MemoryFriendlyCalculation()
{
    for (int i = 1; i <= 40; i++) {
        std::cout << "("<< i <<")" << " " << SlowFib(i) << endl;
    }
}

Fast Calculation - 8ms

WindowsTerminal_sfbNbprULm

long FastFib(int n)
{
    if (_memo.count(n))
        return _memo[n];

    int value = FastFib(n - 1) + FastFib(n - 2);
    _memo[n] = value;

    return value;
}

void FastCalculation()
{
    for (int i = 1; i <= 40; i++) {
        std::cout << "(" << i << ")" << " " << FastFib(i) << endl;
    }
}

About

Performance or Space Which is the best option for your optimization. In this project I created a two path using Fibonacci Calculation for this situation

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages