oguzhandelibas / FibonacciCalculation

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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


Languages

Language:C++ 100.0%