For the Fibonnacci serie that is described like follows: Fibo(0) = 0; Fibo(1)= 1; (base cases) .... Fibo(n) = Fibo(n-1)+Fibo(n-2) Thus: Fibo(2) = 1 + 0 = 1; Fibo(3) = 1 + 1 = 2;... This code computes N term of a Fibonacci serie, using 2 algorithmic techniques: Recursive and Rec-DProgramming, it also measures performance time. fibonacci.h #ifndef FIBONACCI-NUMBER_H_INCLUDED #define FIBONACCI-NUMBER_H_INCLUDED #include #include #include using namespace std; //Fibonnacci recursive int fiboRec(int n){ if(n==0) return 0; if(n (end - start).count() =0 && second>=0) return dp[n] = first + second; else return -6; } int launcherFiboDP(int k) { //dp = (int *) calloc( k+1, sizeof(*dp)); memset(dp, -6, sizeof(dp)); int n = k; ////// auto start = chrono::steady_clock::now(); int r = fiboDP(n); auto end = chrono::steady_clock::now(); ////// cout (end - start).count() > n; cout main.h #include "fibonacci.h...
Top common mistakes for Java developers Reference to the article 1: Neglecting Existing Libraries 2: Missing the ‘break’ Keyword in a Switch-Case Block 3: Forgetting to Free Resources 4: Memory Leaks 5: Excessive Garbage Allocation 6: Using Null References without Need 7: Ignoring Exceptions 8: Concurrent Modification Exception 9: Breaking Contracts 10: Using Raw Type Instead of a Parameterized One Top common mistakes for Java developers when programming C++ Reference to the article 1: Type conversion rules 2: Memory management 3: Deterministic destruction 4: Exception handling
Comments
Post a Comment