How to do an analysis in 5 steps

How to do a Data Structure and Algorithms analysis?

Contents

  1. Example Code
  2. Step 1: Establish variables and functions (mathematical ones)
  3. Step2: Count your operations

Example Code

unsigned int factorial(unsigned int n){
    unsigned int rc = 1;
    
    // we don't start from 1 because multiplying 1*1 gives 1. So start from 2
    for(unsigned int i = 2; i <= n; i++){
        rc = rc * i;
    }
    return rc;

}

Step 1: Establish variables and functions (mathematical ones)

Let n represent the value we are finding the factorial for

Let T(n) represent number of operations needed to find n! using the code

Step2: Count your operations


© 2018. All rights reserved.

Powered by Hydejack v8.5.2