3. How to calculate the time complexity
• The running time of an algorithm depends on
the following factors
– Single Vs multiprocessor
– Read/write speed of memory
– 32 bit architecture Vs 64 bit architecture
– Input size
4. How to calculate the rate of growth of
an algorithm with respect to the input:
• For the calculation purpose, a model machine to be
considered with an assumption of Single processor, 32 bit
architecture, and sequential execution of the Read/Write
operation and the unit of time taken by the arithmetic &
logical operations, assignment operations and return
statement are considered as one.
• Examples 1:
– Sum (a ,b)
– {
– Return a + b
– }
• In the above example, the return statement takes 1 unit of
time; the addition operation takes 1 unit of time. So, the
total time taken is 2 units.
5. Constant Growth
• As per the above, the algorithm grows on
constant time.
• Tn=1
0
0.5
1
1.5
2
2.5
1 2 3 4 5 6 7 8 9 10 11 12 13
RateofGrowthT
Input size n
Rate of Growth of Algorithm
Constant Growth
6. Examples 2:
Statement No. Cost of Execution Time taken in
unit of 1
1 Sum=0; 1 (C1) 1
2 For n=0 to n-1 2 (C2) n+1
3 Sum=sum + A[i]; 2 (C3) n
4 Return Sum 1(C4) 1
Sum (Sum of elements of array A, n)
{
}
As per the above, the algorithm grows as follows,
Tn = 1+2(n+1) + 2n+1
= 4n + 4
= Cn + C` [C= C2+C3 & C`=C1+C2+C4]
8. Example 3:
For “Sum of Matrix “the expression will be
Tn= an2+bn+c
The growth of the algorithm is in the quadratic manner.
0
5
10
15
20
25
30
35
1 2 3 4 5
RateofGrowthT
Input size n
Rate of Growth of Algorithm
Quadratic Growth