Complexity of an Algorithm
Suppose A is an algorithm and n is the size of
input data, the time and space used by the algorithm A are the two main
factors, which decide the efficiency of A.
Time Factor -Time is measured by counting the number of key operations like comparisons
in the sorting algorithm.
Space Factor - Space is measured by the maximum memory space required by the algorithm.
The complexity of an algorithm f (n) gives the
running time and/or the storage space required by the algorithm in terms of n
as the size of input data.
The Time complexity of an algorithm is given by
the number of steps taken by the algorithm to complete the process.
Space complexity of an algorithm is the
amount of memory required to run to its completion. The space required by an
algorithm is equal to the sum of the following two components:
A fixed part is defined as the total space required to store certain data and variables for
an algorithm. For example, simple variables and constants used in an algorithm.
A variable part is defined as the total space required by variables, which sizes depends
on the problem and its iteration. For example: recursion used to calculate
factorial of a given value n.