How to calculate TIME COMPLEXITY of any program || How TIME COMPLEXITY of an algorithm is computed .
The time tp,taken by a program P ,, is the sum of the Compile time and
the Run time(execution time) .The Compile time doesn't depends on the instance
characteristics (it emplies..>>number of input,number of output,magnitude of input,magnitude of output).
tp(n) = CaADD(n) + CsSUB(n) + CmMUL(n) + CdDIV(n)+....
Where n-->instance characteristics. Ca,Cssub>,+ Cm,Cd denotes the time needed for Addition,Subtraction,Multiplication,Division and so on.
Following are the primitive operations that are independent from the programming language are used to calculate the running time :
- Assigning a value to a variable.
- Calling a function.
- Performing an arithmetic operation.
- Comparing two variables.
- Indexing into a array of following a pointer reference.
- Returning from a function.
Quote: