How to do an analysis in 5 steps
Doing mathematical analysis can be intimidating. However, what you are really doing is simply explaining a thought process. This can be done in a fairly consistent step by step manner. This section looks at the steps you should take to do this and break down how to approach an analysis.
Step 0: It is good to start by putting your code in.
unsigned int factorial (unsigned int n){
unsigned int rc = 1;
//multiplying 1*1 gives 1 so we don't start from 1
for (unsigned int i=2;i<=n;i++){
rc=rc*i;
}
return rc;
}
If you are copying code into a markdown wiki page, you can use surround the code block with ``` to do a block quote.
To format according to a language provide the name of the language after the third tick that precedes the block. For example:
```cpp
put your code here. code will be c++ syntax formatted
```
Step 1: Establish variables and functions (mathematical ones):
Let represent the value we are finding the factorial for
Let represent number of operations needed to find using the code
Step 2: Count your operations
Put the operation count in a comment beside each line of the code blurb. The loop runs n-1 times (i goes from 2 to n inclusive). Thus any operations that occur in the loop is counted as n-1.
unsigned int factorial (unsigned int n){
unsigned int rc = 1; // 1
//multiplying 1*1 gives 1 so we don't start from 1
for (unsigned int i=2;i<=n;i++){ //1 + (n-1) + (n-1)
rc=rc*i; //2(n-1)
}
return rc; //1
}
Step 3: Establish the Mathematical Expression for T(n)
We add up the operation counts in the comments
Step 4: Simplify your Equation
Step 5: State your final result.
Therefore, is
Last updated