It is the amount of time which is needed by the algorithm (program) to run to completion. We can measure the time by finding out the compilation time and run time.
The compilation time is the time which is taken by the compiler to compile the program. This time is not under the control of programmer. It depends on the compiler and differs from compiler to compiler. One compiler can take less time than other compiler to compile the same program. So we ignore the compilation time and only consider the run time. The run time is the time which is taken to execute the program. We can measure the run time on the basis of number of instructions in the algorithm.
E.g.
Suppose we want to add two integer numbers. To solve this problem we have following two algorithms:
Suppose 1 second is required to execute one instruction. So the first algorithm will take 4 seconds and the second algorithm will take 3 seconds for execution. So we will choose the second one as it will take less time.
Reasons for studying time complexity
1. The user can be interested in knowing in advance whether the program will provide satisfactory real-time response or not.
2. There can be several solutions for the problem with different time requirements and we have to choose that which takes least time among them.